openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cheng Zhang" <chzh...@yahoo-inc.com>
Subject RE: unexpected update when using many to many relationship
Date Thu, 04 Mar 2010 19:08:34 GMT
Hi Ravi,

Yes, calling getters on Subject within a transaction results in update statements. The update
is on MC_SUBJECT.

I'm using Spring Transaction for the transaction management.

I will try to consolidate some of my code so you can have a full picture how openjpa is used
in this project.

Thanks,
Cheng


> -----Original Message-----
> From: Ravi Palacherla [mailto:ravi.palacherla@oracle.com]
> Sent: Thursday, March 04, 2010 10:02 AM 无住生什么心?
> To: users@openjpa.apache.org
> Subject: RE: unexpected update when using many to many relationship
> 
> 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