-->
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.  [ 5 posts ] 
Author Message
 Post subject: Implement more-than-one-transactions-in-one-session
PostPosted: Mon Apr 23, 2007 2:14 am 
Newbie

Joined: Sun Apr 22, 2007 10:33 pm
Posts: 11
Hi,
I'm using Hibernate version 3.2.0.ga with Hibernate Annotations 3.2.1.ga.
We have a requirement to perform multiple operations as seperate transaction (independently).
The database I'm using is Oracle9i.
That is those operations can be partially successful (even if subsequent operation(s) fail, we don't want to rollback).
That is we are trying to implement one-session-multiple-transactions [anti]pattern. I understand THIS IS AN ANTI PATTERN AND SHOULD BE USED ONLY IN EXCEPTIONAL SCENARIOS.
I've read both:
http://www.hibernate.org/42.html and
http://www.hibernate.org/43.html
But could not get any simple workaround.

We do use Spring IOC to instantiate Hibernate sessionFactory bean (using org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean class) and
and transactionManager bean (using org.springframework.orm.hibernate3.HibernateTransactionManager class).

What is the simplest solution to have:
======== Session01_BEGIN=======
begin Transaction01
doOperation01()
end Transaction01

begin Transaction02
doOperation02()
end Transaction02
======== Session01_END======

Hibernate gurus, any help is appreciated.

_________________
~/Gurram


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 6:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
well if you are outside a container
Transaction tx = session.beginTransaction();
//do stuffs
tx.commit();


tx = session.beginTransaction();
//do stuffs
tx.commit();

I don't know how to handle that with spring though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 3:33 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
Hi,

i have simillar scenario -- I always want to write an "attempt" into a db, even on error.

I just did the same emmanuel has said. I use 'session-per-request' pattern.

Depending on your transaction management (i use both -- programatical as well as transaction proxies) you just simply obtain the referencies to your DAOs and do the work in two different transaction.

Just make sure to test your data to know if there will be/will not be a database error. (In case of db error your session will get closed.)

I always deploy transactional and non-transactional DAO to allow me whatever combination i preferer.

m.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 7:45 pm 
Newbie

Joined: Sun Apr 22, 2007 10:33 pm
Posts: 11
Thanks Mar.

Your approach appears to be the quickest solution for my situation.

_________________
~/Gurram


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 12:55 am 
Newbie

Joined: Sun Apr 22, 2007 10:33 pm
Posts: 11
We are also exploring using "Catch the exceptions before Hibernate/Spring sees them" approach as well. Simply, we are intending to catch exceptions for each DB-Transactions. Effectively, Hibernate/Spring does not encounter any exceptions and doesn't try to roll-back

_________________
~/Gurram


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