Hi, me again. A have some issues with an unidirectional @OneToMany relation Here are the code and results :
//////////////////////////////////////////////////// Entity bean @Entity @Table(name = "MANAGER") public class Manager implements Serializable { protected Collection managedFleets; /** * Get the managedFleets. * @return Returns the managedFleets. */ @OneToMany(fetch = FetchType.LAZY) @JoinTable(name = "FLEET_MGR", joinColumns = { @JoinColumn(name = "MGR_ID") }, inverseJoinColumns = { @JoinColumn(name = "FLEET_ID") }) public Collection getManagedFleets() { return managedFleets; } /** * Set the managedFleets. * @param managedFleets The managedFleets to set. */ public void setManagedFleets(Collection managedFleets) { this.managedFleets = managedFleets; } } /////////////////////////////////////////////////// Session bean public void assignFleetToManager(Integer fleetId, Integer managerId) { Fleet fleet = em.find(Fleet.class, fleetId); Manager manager = em.find(Manager.class, managerId); if ((fleet != null) && (manager != null)) { managedFleets.add(fleet); } } A call to this method on a FLEET already associated to a MANAGER creates a new association and does not delete the OLD association. This leads to a fleet assigned to 2 managers which is no more a OneToMany relation... BEFORE: MGR_ID FLEET_ID 107 5 108 6 AFTER a call to assignFleetToManager(6, 107) MGR_ID FLEET_ID 107 5 107 6 108 6 Another issue is that if a call twice the assignFleetToManager method, jboss does not notice that the relation still exists and insert a new one that produce a SQL exception cause of ducplicate primy keys. What did i miss ? Thank you Christophe. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3925621#3925621 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3925621 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user