-->
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.  [ 1 post ] 
Author Message
 Post subject: Modified object does not flush
PostPosted: Tue Dec 04, 2007 12:16 pm 
Newbie

Joined: Fri Nov 30, 2007 6:29 am
Posts: 14
Location: Oslo
Hibernate version:3.3

Code between sessionFactory.openSession() and session.close():
Spring 2.0.7 HibernateTemplate and HibernateTransactionManager

Name and version of the database you are using:
H2 1.0.59

Hi all,

First of all: apologies if this belongs on the Spring forum; hopefully it will be useful for someone with similar problems. I have this case:

I start a transaction with Spring HibernateTransactionManager, then do the following inside the transaction (part1):
Code:
1. hibernateTemplate.save(object)
2. object.setValue(newValue)
3. hibernateTemplate.execute [...] { return [Query where object.value == newValue]}


Part 1 works just fine: just before the query is executed, the session is flushed with the changes (value = newValue). The query returns the same object that was saved in (1) - the object id is the same, and the value is updated to newValue. If I end the transaction at this point and inspect the database, value is newValue in the database.

Part2 (the same transaction):
Code:
4. object.setValue(anotherValue)
5. hibernateTemplate.execute [...] { return [Query where object.value == anotherValue]}


Here's the strange thing: Just before the sql for the query in (5) executes .... there's no flush of the session with (value == anotherValue). However, the query executes and returns the same object that was saved in (1), and the object has value==anotherValue. When the transaction commits and I check the database, value==newValue.

Obviously, I'd expect the session to be flushed just before I ran the second query as well.

I tried different things without success:
1) Make the transaction propagation nested
2) Manually flush the transaction after the value was set with a new value. Did this with hibernateTemplate.flush(). Saw from the sql log that nothing was flushed.
3) Debugged the transaction to check the hibernate Sessions identity at all points it was used. The id was the same during the whole transaction.
4) Split the operation in two transaction - one for part 1 and one for part 2. That worked as expected (but is however not possible for me to do as this is a unit test which I need to roll back).

Any help appreciated! If you need mappings or code examples, I'll post it (left out for readability).


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

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.