openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravi Palacherla <ravi.palache...@oracle.com>
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 ?

Regards,
Ravi.

-----Original Message-----
From: Cheng Zhang [mailto:chzhang@yahoo-inc.com] 
Sent: Thursday, March 04, 2010 10:38 AM
To: users@openjpa.apache.org
Subject: unexpected update when using many to many relationship

Hi,

 

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

 

Here is my code,

 

@Entity

@Table(name = "MC_SUBJECT")

public class Subject implements Serializable {

    @Id

    @Column(length=64)

    private String id;

 

    @Column

    private Date createdDate;

 

    @Column

    private String createdBy;

 

    @Column(length=128, nullable=false)

    private String title;

 

    @Column(length=128, nullable=false)

    private String subjectType;

 

    @Column(length=2048)

    private String description;

 

    @Column

    private Date modifiedDate;

 

    @Column

    private String modifiedBy;

 

    @ManyToMany(fetch=FetchType.LAZY)

    @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?

 

Thanks,

 

Cheng

 

 


Mime
View raw message