-->
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.  [ 1 post ] 
Author Message
 Post subject: ManageLongTransactions
PostPosted: Sat Dec 11, 2010 9:26 am 
Newbie

Joined: Sat Dec 11, 2010 8:49 am
Posts: 19
Hello,

I am working on Java SE desktop application and use Hibernate for database access.

In my application i have list of objects (beans) and user is capable to add/remove/modify objects from list.
List is displayed in one panel and add/modify dialog is opened when user add new object to the list.
User can wait as long as he wants on add/modify dialog before commit changes. After new object is added
i need to refresh list to include new object.

My idea is to open new session when display list at startup to load all data from database.
session = SessionFactory().openSession();
session.setFlushMode(FlushMode.MANUAL);
Transaction tx = session.beginTransaction();
load(foo);
tx.commit();

I suppose session is now released from JDBC connection and returned to pool?

Then when add/modify dialog is opened i forward same session to add/modify dialog. When user
fill form and press submit button here is what i do:
Transaction tx = session.beginTransaction(); // this is same session as previous
fooDao.persist(newFoo);
session.flush(); // This is last transaction in conversation
tx.commit(); // Also return JDBC connection
session.close();

After that i come back to list of objects again. If i close session as it done after persisting new object
i cannot access anymore my objects on list because session is closed.
But if i don't close session, when i am get back on list everything works just fine and
new objects are added to list but i am not sure is session disconnected now and returned to pool.

What i want is to enable user to list all objects (some objects have other objects lazily loaded) and to
add/modify objects but without keeping session connected to JDBC connection all time, but only when is needed.

Is there any idea how to accomplish this in hibernate?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.