-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate doing update instead of select
PostPosted: Wed Apr 11, 2007 5:45 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Hi

I'm calling the following line of code

Code:
RefLabel result = (RefLabel)getHibernateTemplate().get(RefLabel.class, pk);


For some strange reason, when Hibernate executes this line, rather than generating a 'select' for RefLabel, it actually executes an update, on a completely different object. The object it tries to do an update on is mapped OK (my JUnit tests can use it fine).

Anyone know under which circumstances Hibernate might do this wierd behaviour?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 6:15 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi richardgundersen,

With in the transaction scope if any thing modified in persistent object then hibernate try to synchronies with DB.That cause update statement. So be careful when you are handling any persistent

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 6:26 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Yep, in fact I fixed it just before I saw your message. It's down to this line of code:

getHibernateTemplate().setFlushMode(HibernateAccessor.FLUSH_EAGER);

I had updated the other object so it was dirty (but not ready for saving). So, when I did my read, it saw that the object was dirty and tried to persist it (which caused me problems because it wasn't ready to save).

The fix was to move the read statement to be the first line of code, and then after that I could modify my object and not worry about it being persisted in a half-baked state.

The Hibernate debug was very useful because it showed me the following detail

Code:
DEBUG entity.AbstractEntityPersister - com.lsb.uk.mqs.value.mas.MasProduct.description is dirty
DEBUG entity.AbstractEntityPersister - com.lsb.uk.mqs.value.mas.MasProduct.productStatus is dirty
DEBUG entity.AbstractEntityPersister - com.lsb.uk.mqs.value.mas.MasProduct.lastUpdateDate is dirty
DEBUG def.DefaultFlushEntityEventListener - Updating entity: [com.lsb.uk.mqs.value.mas.MasProduct#671]


Although having debug on EVERYTHING in Hibernate really really slows things down :)

Thanks for the reply


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 7:01 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi richardgundersen,

It is good to see that you have solved problem.

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.