-->
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: queries within the same transaction
PostPosted: Tue Jun 16, 2009 12:42 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Hi all.

I have the following (part of) model:

Code:
public class A {
    Set<B> bs = new HashSet<B>();
    // other fields an public access methods (getters/setters)
}


In the DB exists an A element with one B element related to (via A.bs field).
Now, within a transaction, I have added to a element two B elements more. So a instance (in memory) has three B elements related to, but in the database (not session closed yet) only one.

Code:
// Still in the transaction...
daoB.findByA(a).size();


This sentence returns 3 and I think it should return 1. Why returns 3 if the session is not closed still and I have not done "flush"...

However, if I execute a SQL query via TransactionManager.getConnection() the result is the expected, this is, 1.

Any idea?

_________________
Born to lose... live to win!


Top
 Profile  
 
 Post subject: Re: queries within the same transaction
PostPosted: Fri Jun 19, 2009 7:03 am 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
I think I know what happens.

Like I load the A element within a transaction, when I modify it adding B elements, Hibernate returns the new state when I query the DB, because it does not read from DB but form A memory instance.

So, effectively, what I need is to raise a SQL query via jdbc connection.

Bye.

_________________
Born to lose... live to win!


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.