-->
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: multiple transaction in a single session
PostPosted: Tue Apr 01, 2008 5:00 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Hello,

I've two tables in a single database : Products and Customers. They are mapped to the classes Product and Customer.
I would like to load, modify and update the data from the both tables separately (i.e not at the same time).

For example, I would like to :
- first, load the data from Products
- then execute some code with the objects of type Product
- then load the data from Customers
- then upload the modifications from the object of type Product to the db.
- then execute some code with the objects of type Customers
- then upload the modifications from the object of type Customers to the db.

How can I achieve this ? Is it possible to open several transaction in a single session ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 2:26 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can evict objects from the session, but then you have to save them again:

session.Evict(obj);
...
work on the ojects
...
foreach changed object
session.Update();

In this scenario, you have to check manually if the objects have changed, otherwise you get unnecessary updates to the db.

Can't you use two sessions ? That would be a much nicer and cleaner way to solve that. But I guess you wouln't have asked, if you could.

_________________
--Wolfgang


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.