jpa - Hibernate many to many removing entries in join table while update owner table -


i trying update entity having many many relationship table.

           @entity(name = "coaching")          public class coachingentity {   @manytomany(fetch = fetchtype.lazy, cascade = { cascadetype.refresh })     @jointable(name = "coaching_field", joincolumns = @joincolumn(name = "coachingid",    referencedcolumnname = "coachingid"), inversejoincolumns = @joincolumn(name = "fieldid", referencedcolumnname = "fieldid"))    private set<fieldentity> fieldentitylist; 

now, when update coachingentity, hibernate removing entries coaching_field table (many many join table). have searched in internet (jpa update many-to-many deleting records) not able find right approach. in jpa many many merge on owner triggers delete on join table, tried recommended approach used set facing same problem. per https://stackoverflow.com/a/1078295/2116229, need override equals , hashcode?

you need overwrite equals() , hashcode() in entities or going run issues sooner or latter, specially if entities part of set.

see more details: https://community.jboss.org/wiki/equalsandhashcode

if problem persists after overwriting equals() , hashcode() , using bidirectional relationship; then, may need add mappedby on other side of relationship , "link" both objects before persisting. @ answer more details: hibernate (4.1.2) , spring (3.1.2) – manytomany relationship not store records in jointable


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo