-->
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.  [ 10 posts ] 
Author Message
 Post subject: Using Container Managed Transactions with EJBs on Websphere
PostPosted: Wed Jan 21, 2004 7:48 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Hi - I am experimenting with the transaction handling in Hibernate in conjunction with Container Managed Transactions with EJBs deployed on Websphere 5.0.

I have the following settings in my hibernate.xfg.xml:

Code:

<property name="hibernate.connection.driver_class">
COM.ibm.db2.jdbc.app.DB2Driver</property>
<property name="hibernate.connection.url">jdbc:db2:sample</property>
<property name="hibernate.connection.username">db2admin</property>
<property name="hibernate.connection.password">db2admin</property>
           
<property name="dialect">net.sf.hibernate.dialect.DB2Dialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>

<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>



I have a session bean that is deployed with Container Managed Transactions, and RequiresNew on the method that calls my DAO which contains my Hibernate code.

When I call session.beginTransaction() in my DAO I get the following exception:
Code:
net.sf.hibernate.transaction.JTATransaction  TRAS0014I: The following exception was logged javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".


Assuming that the UserTransaction is java:comp/UserTransaction in Webpshere, which I think it is, then what does this mean?

Have I configured this correctly? Is what I am trying to do a valid use of Websphere transactions with Hibernate? How do I get Hibernate transactions to participate in the same transaction that is started by my EJB?

Thanks,
Kevin Hooke


Top
 Profile  
 
 Post subject: Re: Using Container Managed Transactions with EJBs on Websph
PostPosted: Thu Jan 22, 2004 5:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
khooke wrote:
Have I configured this correctly? Is what I am trying to do a valid use of Websphere transactions with Hibernate? How do I get Hibernate transactions to participate in the same transaction that is started by my EJB?

Except that you don't delegate conection retrieval to a WS Datasource, I don't see any pb.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Using Container Managed Transactions with EJBs on Websph
PostPosted: Thu Jan 22, 2004 2:14 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
emmanuel wrote:
Except that you don't delegate conection retrieval to a WS Datasource, I don't see any pb.


Emmanuel - Can you explain what you mean by this statement - do I need to delegate connection retrieval to a Datasource? If so, how do I do this?

I also need to further understand the relation bewteen Container Managed transactions and Hibernate transactions:

- if a transaction has already been started by a Session Bean with Container Managed Transactions and then I execute some Hibermate code, does it implicitly take part within that same transaction, or do I still need to explicitly call beginTransaction() for the Hibernate code to take part within the same transaction?

On a similar note, if an exception occurs within the Hibernate code and I am within a Container Managed transaction, the EJB transaction will be rolled back. Do I explicitly need to rollback the Hibernate transaction, or will a rollback occur as part of the EJB transaction rollback?

Thanks, Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 4:49 pm 
Newbie

Joined: Sun Jan 18, 2004 10:00 am
Posts: 3
could you try:
<property name="jta.UserTransaction">
UserTransaction</property>

instead of :
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>

can you post the result if this works, i am also very interested to see if this works. Unfortunately I get other problems under WSAD 5.1.1 (trial)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 5:02 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
robin wrote:
could you try:
<property name="jta.UserTransaction">
UserTransaction</property>

instead of :
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>

can you post the result if this works, i am also very interested to see if this works. Unfortunately I get other problems under WSAD 5.1.1 (trial)


Thanks for the suggestion.

I've found out that my original config does actually work, providing a transaction has not already been started by the container. For example, if an Action subclass calls the DAO directly, then the code works as I posted.

If an EJB with container managed transactions calls the DAO while it is already in a transaction, then this config and code fails.

Which leads me to wonder that maybe I don't fully understand the use of Hibernate's transactions yet - I have posted another question regarding this here:

http://forums.hibernate.org/viewtopic.php?t=927303


Top
 Profile  
 
 Post subject: Re: Using Container Managed Transactions with EJBs on Websph
PostPosted: Thu Jan 22, 2004 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
khooke wrote:
Emmanuel - Can you explain what you mean by this statement

Check the 3.4 section in the ref guide it show configuration of JDBC call vs Datasource call

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 9:10 am 
Newbie

Joined: Sun Jan 18, 2004 10:00 am
Posts: 3
You said that the code fails if a container manager transaction is underway. But is there no way to use Hibernate in a J2EE env. while making use if the container managed transactions?
Or the put it in another way. I think the Container Managed Entity Bean are much too complex, but the container managed transactions are great.
Does anyone has small example how to use Hibernate in J2EE env without making explicit calls like transaction.start() transaction.commit() that's something the container should manage.

thank you in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 1:25 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
robin wrote:
But is there no way to use Hibernate in a J2EE env. while making use if the container managed transactions?

Robin - see this post here:
http://forum.hibernate.org/viewtopic.php?t=927303


Top
 Profile  
 
 Post subject: I am having the same problem
PostPosted: Wed Mar 03, 2004 11:25 pm 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
Hi,

I am having the same problem when beginning a transaction. Also using WebSphere and MySQL.

My call starts in a Session bean and is then delegated to a POJO which is my Persistence Manager. If I remove the transaction code and just use session.flush(), everything works, but if I try to open a transaction I can't find the UserTransaction in JNDI.

I have tried changing my JNDI property to just UserTransaction instead of java:comp/UserTransaction and I get the same error. I have also successfully looked up the java:comp/UserTransaction using the built in JNDI context browser and it is found without problem.

I have read this thread and the one being referenced but am still confused as to what this thread really concluded to be the solution...?

How can I keep the transaction code in my persistence manager for container portability and have it work in WebSphere?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 5:39 pm 
Newbie

Joined: Tue Feb 03, 2004 11:58 am
Posts: 11
How do I set the JNDI name for jta:UserTransaction in WSAD5.0


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