The following seems to work for me:
| @Entity | @Table(name = "ModuleProperty") | public class ModuleProperty implements Serializable { | | /** | * | */ | private static final long serialVersionUID = 1L; | | ModulePropertyPK id; | | Module module; | | String value; | | public ModuleProperty() { | super(); | id = new ModulePropertyPK(); | } | | public String getValue() { | return value; | } | | public void setValue(String value) { | this.value = value; | } | | @EmbeddedId | @AttributeOverrides({ | @AttributeOverride(name="moduleID", [EMAIL PROTECTED](name="MODULEID")), | @AttributeOverride(name="name", [EMAIL PROTECTED](name="NAME")) | }) | public ModulePropertyPK getId() { | return id; | } | | public void setId(ModulePropertyPK id) { | this.id = id; | } | | @ManyToOne() | @JoinColumn(name="MODULEID",updatable=false,insertable=false) | public Module getModule() { | return module; | } | | public void setModule(Module module) { | this.module = module; | id.setModuleID(module.getModuleID()); | } | | @Column(name="NAME",updatable=false,insertable=false) | public String getName(){ | return id.getName(); | } | | public void setName(String name){ | id.setName(name); | } | } | using @Column(updatable=false,insertable=false) helped with mapping the FK to the field in composite key. However on the SLSB side I have to do the following to update changes to module properties: | public Module updateModule(Module m) { | try { | Module module = em.find(Module.class,m.getModuleID()); | Logger.getLogger(this.getClass()).info( | "Updating module: " + m.getModuleID()); | Map<String, ModuleProperty> properties = m.getProperties(); | Map<String, ModuleProperty> props = module.getProperties(); | for (ModuleProperty p : properties.values()) { | if(!props.containsKey(p.getName())){ | p.setModule(module); | em.persist(p); | props.put(p.getName(),p); | } else{ | props.get(p.getName()).setValue(p.getValue()); | em.merge(props.get(p.getName())); | } | } | Set<String> keysToRemove = new HashSet<String>(); | for(String key: props.keySet()){ | if(!properties.containsKey(key)){ | keysToRemove.add(key); | } | } | for(String key: keysToRemove){ | em.remove(props.get(key)); | props.remove(key); | } | module.setProperties(props); | em.merge(module); | return module; | } catch (Exception ex) { | ex.printStackTrace(); | } | return null; | } | If I don't do this the update throws batch update exception. I would assume that merge should have handle that. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3946591#3946591 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3946591 ------------------------------------------------------- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user