openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Luis Cetina <maxtorz...@gmail.com>
Subject ManyToMany tries to insert twice
Date Wed, 24 Sep 2014 20:44:51 GMT
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*
-------------------------------------------------------------------

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message