-->
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.  [ 3 posts ] 
Author Message
 Post subject: entitymanager - transaction, commit, flush
PostPosted: Sat Sep 13, 2008 7:59 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
Hi
I have a question of the right usage of entity manager (EM).

i have a complex entity that contains list of sub entities.
i want to implement manual commit thingy. so i pesrsist entities then somewhere afterwards i do either em.flush() or em.getTransaction().rollback().

but something is wrong here for me.

when i create entity manager, should i do em.getTransaction().beginTransaction()?

when i try to persist the complex object, the list of sub objects is being emptied in the proccess. Doesnt it persist i nrecursion for sub entities too?
Even if i persist the sub entities first it still empties my list... on the complex persist..

in addition there is em.getTransaction().commit(); should i use it instead of em.flush() or not?

thanks.
Hope to get understand what is the right thing to do ...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2008 3:07 pm 
Newbie

Joined: Wed Jul 25, 2007 6:33 pm
Posts: 9
First of all, my suggestion is you create a unit test and find out yourself. You can see what Hibernate is doing by following the SQL logs.

Secondly, for any modifications to be actually committed you need to begin a transaction and commit it. "flush()" just tells Hibernate to issue the SQL commands, it does not do a commit to the database.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 13, 2008 5:27 pm 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
I read in the api that flush synchronizing stuff to the database.

Anyway i am doing em.getTransaction().begin()
and em.getTransaction().commit();

My question is what shall i do with persist() it wont persist my sub objects.
(even when they are already managed)

p.s.
i got unit testing, it doesnt help me to understand the concept


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