-->
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: Simple question - HQL and flushing in transactions
PostPosted: Mon Jun 18, 2007 6:26 pm 
Newbie

Joined: Thu Sep 16, 2004 9:03 am
Posts: 8
I have a simple question:
When working in a transaction, should an HQL Named Query flush the session before returning a list of objects?


In pseudo-code (given an entity of type 'A'):

1. Begin transaction
2. Create a new instance of A
3. session.save(the new instance of A);
4. HQL to try to load A
5. Commit transaction


Should the HQL be able to find the new instance of A? I haven't been able to get it to work...

This is related to this other post which I found:
http://forum.hibernate.org/viewtopic.ph ... +flushmode


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 3:56 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>>When working in a transaction, should an HQL Named Query flush the session before returning a list of objects?
Yes. NO.
We have a say in it.
It depends on session's FLUSH mode.

>> Should the HQL be able to find the new instance of A?
Yes.

>> I haven't been able to get it to work.
Just check you session's flush mode.
In AUTO mode, it works fine. I have set up a small example for the same.

-----------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject: tracking down the problem
PostPosted: Tue Jun 19, 2007 9:59 am 
Newbie

Joined: Thu Sep 16, 2004 9:03 am
Posts: 8
Thanks for the reply.

I am still having problems, but am tracking them down.

Right now, the status is that the code works with hibernate 3.1.1 but does not work with 3.2.4 sp1.

In turning up the logging I have found that for 3.2.4, the following hibernate code is not executed:
-----------------------------------------------
2007-06-19 09:02:17,354 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
2007-06-19 09:02:17,354 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
---------------------------------------------------

I'm tracing into the source now to figure out why its being called in the old code, but not the new code.

I am using FlushMode.AUTO everywhere (and have verified via the debugger at runtime).

Thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 11:14 am 
Newbie

Joined: Thu Sep 16, 2004 9:03 am
Posts: 8
I tracked down the problem. In the newer version of hibernate, the session is only flushed if a transaction is active. I looked through my stack trace and the transactions were being created appropriately by Spring and wrapping my hibernate invocations.

The problem ended up being that I had by accident declared the wrong type of transaction manager. I had been using:
org.springframework.jdbc.datasource.DataSourceTransactionManager
when I (obviously) should have been using:
org.springframework.orm.hibernate3.HibernateTransactionManager

Just a mistake on my part in grabbing the wrong class... hopefully this helps someone else track down a similar problem.

Thanks


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.