-->
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.  [ 11 posts ] 
Author Message
 Post subject: can you abort a transaction after flush
PostPosted: Fri Nov 10, 2006 6:43 pm 
Newbie

Joined: Fri Nov 10, 2006 6:37 pm
Posts: 9
In the transaction-per-session scenario (or even otherwise), what happens if you flush the session and then the transaction has to be aborted?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 11, 2006 3:15 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
I think this should be rolled back as well. What counts is when the rollback occours in the database.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:26 pm 
Newbie

Joined: Fri Nov 10, 2006 6:37 pm
Posts: 9
Its not clear why you would want to flush the session in the middle of your processing? Looks like the only time flush is needed is before commit().

A related question: when you do a hibernate query, is the updated data in your session available to query if you haven't done the flush() yet?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 7:49 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Quote:
A related question: when you do a hibernate query, is the updated data in your session available to query if you haven't done the flush() yet?

It should be able since a query triggers a flush, unless you specify something different.

Quote:
Its not clear why you would want to flush the session in the middle of your processing? Looks like the only time flush is needed is before commit().

For most scenarios this is true. But if you have code that for instance needs an id created by a sequence before the transaction ends you will have to flush earlier.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
MikePloed wrote:
Quote:
A related question: when you do a hibernate query, is the updated data in your session available to query if you haven't done the flush() yet?

It should be able since a query triggers a flush, unless you specify something different.

Quote:
Its not clear why you would want to flush the session in the middle of your processing? Looks like the only time flush is needed is before commit().

For most scenarios this is true. But if you have code that for instance needs an id created by a sequence before the transaction ends you will have to flush earlier.

Actually id generation is not a good usecase since it gets generated right away (no flush needed).
But working on massive amount of data in a single transaction or early catch of optimistic locking issue is.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 10:36 am 
Newbie

Joined: Fri Nov 10, 2006 6:37 pm
Posts: 9
> But working on massive amount of data in a single transaction or early catch of optimistic locking issue is.

I understand the need to flush (and clear) while working on massive amount of data in a single transaction ... to keep your session memory/cache limited.

Why do you need flush for optimistic locking?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:21 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Quote:
Actually id generation is not a good usecase since it gets generated right away (no flush needed).

This is an interesting point. In a recent project we needed to flush earlier due to ID not being generated right away. I'll check that with a small test case on my box...

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it can be the case for persist if you are out of transaction. But if you are out of tx, you don't want to flush

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 11:50 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Of course. Actually in a small test case and in our full app ids get assigned after calling save.

Sorry, Emmanuel you were absolutely right. We are flushing earlier for calculated values which have to be stored in the db and have to be passed to the DTO mapper. Calculation is being done by Interceptor#preFlush()...

I think I have to reread my JB world berlin slides because I remember having early flushes in them. Thanks a lot!

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 12:06 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Actually I found a use case regarding ID generation where you need to flush earlier in order to get the id:

ObjectA references ObjectB in a <many-to-one cascade="all" ..> relationship.

Initially ObjectB is not saved. After loading ObjectA from the database using session.get(..) I create a new ObjectB and add it to object a without calling session.saveOrUpdate(objectA).

In this case ObjectB get's the id upon calling transaction.commit() and not right away.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah yes, transitive persistence requires a flush

_________________
Emmanuel


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