-->
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: Which transaction attribute for a finder method in CMT?
PostPosted: Tue Jun 27, 2006 4:27 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
Hi,

I'm currently developping an EJB (CMT) which uses hibernate for persistence. This ejb contains state-modifying methods (update, save) and finder / query methods which do not alter the system state.

For update methods, the transaction attribute to use would be something like REQUIRED or REQUIRES_NEW but what about finder methods? As long as those do not change anything, I thought I could use NOT_SUPPORTED... but if I do this, Hibernate won't be able to bind the session to the current transaction (because there's no transaction) and I won't be able to use SessionFactory.getCurrentSession().

So depending on which operation I would like to do (update or find), I would handle sessions differently (SessionFactory.getCurrentSession() in the first case, try / catch block with SessionFactory.openSession() and Session.close() in the second case).

I would like to know if other people encountered this problem.

thanks a lot,
Xavier


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 8:13 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Personally I would always want a transaction no matter what. If your hibernate 'finder' method throws an exception there is probably something seriously wrong with your system anyway.

In special circumstances where you may want a single process to coordinate seperate (transactional) units of work, you could use an EJB with a NotSupported method, which in turn calls other EJB methods (that interact with Hibernate) with Required transaction.

I think you must have a transaction if using hibernate with CMTTransactionFactory, or you could take a look at JTATransactionFactory.

Hope that helps


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