-->
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: Re: UserTransaction Problem
PostPosted: Tue Nov 21, 2006 10:14 am 
Newbie

Joined: Tue Mar 28, 2006 10:34 am
Posts: 2
Hi,

i am trying to get the UserTransaction working with Hibernate, but having massive problems in resolving my issues.

I already did what has been written in hibernate tutorials with usertransactions and jboss, but hibernate won't synchronize with the JTA.

Generally i do the following in my application:
0) SessionFactory set up
1) In each Constructor of a bean: getting the UserTransaction and beginning it (works without hibernate)
2) try to get the current session in hibernate (won't work-->Exception)
3) try to use the getters and setters of my loaded objects (won't work because of 2)
4) in finalize method of each bean: commit the transaction (won't work because of 2 - but without hibernate it works fine)

I try to get hibernate not to load the complete object-path at once. I thought to use jbossusertransaction and wrap my application with it (step 1-4): If i call a get-method of my objects in step 3) hibernate will load it once the get-method is accessed. But i won't get that far because i am stuck in 2).

Maybe i did something wrong or somebody knows a better way to use transactions in jboss with hibernate.

Many thanks in advance,

Ingo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 1:45 pm 
Newbie

Joined: Tue Nov 21, 2006 1:32 pm
Posts: 2
Location: Germany
It would be of some help to post the exact exception you got in step 2.


Am I understanding you correctly?
point 2) says: you are creating a new transaction in the constructor of your persistent entities.

If that's true, that is of course the reason for your problem.

If you want to work with UserTransaction the general usage pattern is like that:

1. Start your transaction in your service bean or DAO and therin at the begin of a service method, not in the constructor.
2. Call SessionFactory.getCurrentSession() and work with it.
3. At the end of your service method call commit() or rollback() on the UserTransaction.

Normally their is absolutely no reason to access the UserTransaction from within persistent objects aka entities.


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.