openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravi Palacherla <>
Subject RE: unexpected update when using many to many relationship
Date Thu, 04 Mar 2010 18:02:25 GMT
Hi Cheng,

>> I just read some Subject records
Do you mean calling getters on Subject with in a transaction, results in update statement
I do not think it is an expected behavior.

Is the update statement on "MC_SUBJECT" table ?
I understand from the code snippet you pasted; that it a self-referential many2many relationship
between subject and subject, correct ?
I think pasting the code snippet that reads subject records ( actually all the code that is
called inside the transaction) will help.

Also what type of persistence context are you using, extended or transaction ?


-----Original Message-----
From: Cheng Zhang [] 
Sent: Thursday, March 04, 2010 10:38 AM
Subject: unexpected update when using many to many relationship



I found that, if I use many-to-many relationship, there will be
unexpected update when the transaction is closed.


Here is my code,



@Table(name = "MC_SUBJECT")

public class Subject implements Serializable {



    private String id;



    private Date createdDate;



    private String createdBy;


    @Column(length=128, nullable=false)

    private String title;


    @Column(length=128, nullable=false)

    private String subjectType;



    private String description;



    private Date modifiedDate;



    private String modifiedBy;



    @JoinTable(name = "MC_CHILD_SUBJECT", joinColumns = {
@JoinColumn(name = "SUBJECT_KEY") }, inverseJoinColumns = {
@JoinColumn(name = "CHILD_SUBJECT_KEY") })

    private List<Subject> childSubjectCollection;


...... getters and setters



In my code, I just read some Subject records. In the log file, I can see
some update statement.


However, if I change the many-to-many to one-to-many, everything is fine
and no update.


Is it expected behavior?







View raw message