users@glassfish.java.net

ManyToMany insert/update jointable

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Feb 2007 16:25:44 PST

I've got the following scenario, and am a bit stumped...

I have 3 three tables in my schema...
  person
  group
  person_group

The person_group table is an association table and consists solely of person_id and group_id foreign keys.

I designed the entities as follows:

@Entity
public class Person{
   @ManyToMany
   @JoinTable(name="person_group", joinColumns={_at_JoinColumn(name="person_id")},inverseJoinColumns={_at_JoinColumn(name="group_id")})
   private Set<Group> groups;
}


@Entity
public class Group{
   @ManyToMany(mappedBy="groups")
   private Set<Biomarker> biomarkers;
}

I want to do something like the following:
Person person = new Person();
person.setId(1); // This person exists in the database already
Group group = new Group();
group.setId(1); // this group exists in the database already
Set groups = new HashSet();
groups.add(group);
person.setGroups(groups);
em.merge(person);

I'm trying to persist the person object and cascade inserts/updates to the jointable (person_group). I won't have made changes to the Group metadata, so I don't want to update the group table, just insert/update/delete records from the person_group table.

I've tried various combinations of configurations, and am stumped at this point.

Any help is greatly appreciated.

Shannon.
[Message sent by forum member 'smmcneill' (smmcneill)]

http://forums.java.net/jive/thread.jspa?messageID=203545