-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate SQLQuery not retrieving data from database
PostPosted: Mon Aug 08, 2011 3:15 pm 
Newbie

Joined: Thu Sep 22, 2005 1:31 pm
Posts: 3
I have a large legacy system that uses hibernate in a somewhat unconventional way.

Basically, one thread hangs on to a connection taken from the hibernate session and performs batch jdbc inserts into a table. (I won't get into why this happens but just that it was due to performance considerations).
Another thread uses hibernate's SQLQuery object to retrieve data from that same table.

So here's what seems to happen
- thread 1 writes the data to the table
- I confirm the data is in the table by doing a select from a separate db client
- thread 2 tries to read that data and sees nothing even though the data is there

I tried one other thing which was
- I manually insert the data to the table from my db client
- thread 2 tries to read that data and returns successfully


The problem is probably related to the writing thread's use of hibernate. While the connection is committed, perhaps the hibernate session should be have a beginTransaction and transaction.commit as well?

Thoughts?


Top
 Profile  
 
 Post subject: Re: Hibernate SQLQuery not retrieving data from database
PostPosted: Mon Aug 08, 2011 9:05 pm 
Newbie

Joined: Thu Sep 22, 2005 1:31 pm
Posts: 3
I was able to fix the problem even though I'm not exactly sure why this works.

I just wrapped thread 2's query in a transaction, and now it retrieves the data successfully.

What's the purpose of wrapping a single query within a transaction?


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