Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 813759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:24:43+00:00 2026-05-15T01:24:43+00:00

I having problems saving many to many relationships to a pivot table. The way

  • 0

I having problems saving many to many relationships to a pivot table.

The way the pojos are created is unfortunately a pretty long process which spans over a couple of different threads which work on the (to this point un-saved) object until it is finally persisted. I associate the related objects to one another right after they are created and when debugging I can see the List of related object populated with their respective objects. So basically all is fine to this point. When I persist the object everything get saved except the relations in the pivot table.

mapping files:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.thebeansgroup.jwinston.plugin.orm.hibernate.object">
    <class name="ShowObject" table="show_object">
        <id name="id">
            <generator class="native" />
        </id>
        <property name="name" />
        <set cascade="all" inverse="true" name="venues" table="venue_show">
            <key column="show_id"/>
            <many-to-many class="VenueObject"/>
        </set>
    </class>
</hibernate-mapping>

and the other

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.thebeansgroup.jwinston.plugin.orm.hibernate.object">
    <class name="VenueObject" table="venue_object">
        <id name="id">
            <generator class="native"/>
        </id>
        <property name="name"/>
        <property name="latitude" type="integer"/>
        <property name="longitude" type="integer"/>
        <set cascade="all" inverse="true" name="shows" table="venue_show">
            <key column="venue_id"/>
            <many-to-many class="ShowObject"/>
        </set>
    </class>
</hibernate-mapping>

pojos:

public class ShowObject extends OrmObject
{

    private Long id;
    private String name;
    private Set venues;

    public ShowObject()
    {
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Set getVenues()
    {
        return venues;
    }

    public void setVenues(Set venues)
    {
        this.venues = venues;
    }
}

and the other:

public class VenueObject extends OrmObject
{

    private Long id;
    private String name;
    private int latitude;
    private int longitude;
    private Set shows = new HashSet();

    public VenueObject()
    {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public int getLatitude()
    {
        return latitude;
    }

    public void setLatitude(int latitude)
    {
        this.latitude = latitude;
    }

    public int getLongitude()
    {
        return longitude;
    }

    public void setLongitude(int longitude)
    {
        this.longitude = longitude;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Set getShows()
    {
        return shows;
    }

    public void setShows(Set shows)
    {
        this.shows = shows;
    }
}

Might the problem be related to the lack of annotations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:24:44+00:00Added an answer on May 15, 2026 at 1:24 am

    Couple things to try:

    1. You have inverse="true" on both ends of many-to-many. It should be only at one end.

    2. Make your sets not lazy.

    3. You didn’t specify column property for many-to-many tag.

    So it should look something like this at the end:

    <class name="ShowObject" table="show_object">
        ...
        <set lazy="false" cascade="all" name="venues" table="venue_show">
            <key column="show_id"/>
            <many-to-many class="VenueObject" column="venue_id" />
        </set>
    </class>
    
    <class name="VenueObject" table="venue_object">
        ...
        <set lazy="false" cascade="all" inverse="true" name="shows" table="venue_show">
            <key column="venue_id"/>
            <many-to-many class="ShowObject" column="show_id"/>
        </set>
    </class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.