Sorry about this post, the problem was because i set wrong the join and inverse columns.
Thanks. 2014-09-24 15:44 GMT-05:00 José Luis Cetina <maxtorz...@gmail.com>: > > Hi, im not sure if i have a clear concept about the Many to Many persist. > > I have this scenario. > > > table: courses > -course_id > -description > > table: documents > -docuemnt_id > -description > > table: courses_documents > -course_id > -docuemnt_id > > Then my entities: > > public class Course{ > > private int courseId; > > @ManyToMany(cascade = CascadeType.ALL) > @JoinTable(name = "courses_documents", > inverseJoinColumns = > @JoinColumn(name="course_id"), > joinColumns= > @JoinColumn(name="document_id")) > private Set<Document> documents; > > } > > public class Document{ > > private int documentId; > > @ManyToMany(mappedBy="documents" > private Set<Course> courses; > } > > > > Then when i want to persist i did this. > > Course course = em.merge(aCourse); > > //i get a reference of an existed document > Document doc1 = entityManager.getReference(...); > > //then i add that document to course > course.getDocuments().add(doc1); > > > then jpa tries to insert twice in courses_documents why twice?? > > Thanks > > > -- > ------------------------------------------------------------------- > *José Luis Cetina* > ------------------------------------------------------------------- > -- ------------------------------------------------------------------- *José Luis Cetina* -------------------------------------------------------------------