-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: SQL updates on just reads
PostPosted: Fri Mar 03, 2006 3:58 pm 
Newbie

Joined: Tue Dec 28, 2004 7:41 pm
Posts: 7
Hibernate version:
3.1
Annotations 3.1 beta 6

Name and version of the database you are using:
MySql 4.1.14-standard


I have a two entities that share a one-to-many bi-directional relationship. When I do a simple find by ID on the entity on the many side, once my transaction commits I notice not only the select for the entity on the many side but an update for the other entity. No where in my code am I saving or updating the object. If I specify the annotiation fetch type as eager or lazy then the update statement doesn't happen.

After explicitly setting all my fetch types there is still a situation that causes the update to occur but I haven't pinpointed the culprit yet. What would cause hibernate to generate an update statement when neither a save or update occurs in the transaction?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:08 pm 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Its a common misconception on your first steps with hibernate.

Bear in mind that your declared classes are effectively managed by Hibernate. Therefore any changes that you make to the defined properties of the POJO will implicitly perform a save/update.

Are you changing any properties of your retrieved POJOS?

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject: That probably explains my problem now
PostPosted: Fri Mar 03, 2006 4:32 pm 
Newbie

Joined: Tue Dec 28, 2004 7:41 pm
Posts: 7
Thanks for the response. I wasn't aware of that and that may explain my issue now. However it doesn't explain how I was able to get rid of the update in the first scenario by setting the fetch type to EAGER or LAZY. What exactly determines whether an entity is modified?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 8:52 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
It has nothing to do with EAGER or LAZY per se. (please correct me if I'm wrong)

I'm not sure exactly how Hibernate decides when to issue an update before the next select so I'll leave the experts to it ;)

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject: Figured out the problem
PostPosted: Mon Mar 06, 2006 5:15 pm 
Newbie

Joined: Tue Dec 28, 2004 7:41 pm
Posts: 7
I'm not sure why specifying the fetch type would have teporarily solved the problem but the issue was with a bad equals method in a user type. Whenever the field was not set the type's equals method erroneously returned false and caused the entity to appear dirty. I fixed the method and now no update occurs.


Top
 Profile  
 
 Post subject: Disable
PostPosted: Thu Apr 06, 2006 4:05 pm 
Newbie

Joined: Thu Apr 06, 2006 4:01 pm
Posts: 7
Hi,

I have the some problem. Is there any way to disable this "automatic detecting" ?

If I override the "equals()" method of my POJO class, could I solve this problem?

thx

Anderson Araujo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 4:24 pm 
Newbie

Joined: Tue Dec 28, 2004 7:41 pm
Posts: 7
I very much doubt it. My issue was that I overrided the equals and hashcode method and introduced a bug. Once I fixed the methods there weren't any issues. If you didn't override the equals or hashcode method then I assume you have some sort of other unrelated bug which you might want to start another thread for.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.