-->
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: Hibernate Performing Updates on Selects
PostPosted: Wed Feb 14, 2007 10:51 am 
Beginner
Beginner

Joined: Wed Feb 14, 2007 10:43 am
Posts: 21
I have a simple Spring unit test where I initialize my domain tables.

test(){
initTables();
this.setComplete(); // not required but do it any way for test
}

At the end of the test, I see selects for the 3 tables, but for the 2nd table I also see x number of updates (x number of rows in 2nd table). What's happening. There are no updates in my initTables() method.


3.2:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 12:14 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
if you're changing the data on the way in(interceptor, changed setter method, etc.) hibernate notices this and persists the changes to the db.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 2:51 pm 
Beginner
Beginner

Joined: Wed Feb 14, 2007 10:43 am
Posts: 21
Thanks for a reply. I am not very clear what you mean by "changing the data on the way in". I use Spring HibernateTemplate to findAll of that table and dump into a list. I did have a custom implementation of Hibernate Interceptor. But removed that to confirm if that was causing it, but no, that didn't change anything. Updates still happened. And strange thing, it happens to only one table. I am not sure how could I be changing the data in. This happens only when there is "this.setComplete".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 2:58 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
like, if you change the index values on a collection in the setter that hibernate uses, or you have a CustomUserType trimming strings or something, or you reorder a collection; sometimes it's a way less obvious change. If thsoe are called when you're loading something, hibernate notices the change and immediately persists them before the session is closed.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 3:14 pm 
Beginner
Beginner

Joined: Wed Feb 14, 2007 10:43 am
Posts: 21
Chris, that worked. In one of my getters, I had the following logic. If data is not null, return trimmed string value. I removed that and do not see any updates. But now the BIG question is - I may still need to put that logic on the getter. How can this situation be avoided?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 3:33 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
that my friend, is a problem for all of us.

Just gotta bite the bullet somewhere. Either on display superficial to the bean, or take the updates and hope you can lessen the amount of strings that need to be trimmed.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 4:03 pm 
Beginner
Beginner

Joined: Wed Feb 14, 2007 10:43 am
Posts: 21
Thanks Chris.


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.