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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate and Oracle XA for container-managed transactions
PostPosted: Mon Dec 15, 2003 5:41 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
I'm trying to get Hibernate to use WebLogic 8.1's JTA for transaction management with Oracle 9.2, but they don't appear to be interacting properly. I believe the problem is because Hibernate is creating vanilla OracleConnections rather than OracleXAConnections -- I am not using a WLS-managed data source (which does work, but which is not how I want to manage my DB connections) but am instead allowing Hibernate to directly mange Oracle connections.

I specified that Hibernate should use the OracleXADataSource driver class... what else do I need to do to get Hibernate to create XA connections?

Here's my hibernate.xml:

Code:
<hibernate-configuration>
    <session-factory name="jbpmSessionFactory">

        <property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>

        <property name="jndi.url">t3://localhost:7001</property>
        <property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>

        <property name="jta.UserTransaction">javax/transaction/UserTransaction</property>
        <property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
        <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>

        <property name="connection.driver_class">oracle.jdbc.xa.client.OracleXADataSource</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:NBOYDLAP</property>
        <property name="connection.username">jbpm</property>
        <property name="connection.password">jbpm</property>

        <property name="jdbc.batch_size">0</property>
        <property name="statement_cache.size">5</property>
        <property name="show_sql">true</property>
       
    </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 7:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you don't use the JTA manager - what good is it to use XA version of the connection ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
There is alot more involved in getting the full JTA 2PC working from an application server. It will not be possible without an external service provider. In my experience Oracle also has its own ideas in terms of using the drivers data strictures for the Transaction ID etc which usually complicates getting it to work. At the minimum you will need a XA transaction manager. I would suggest you stick with weblogics version as a managed datasource. If you are going external then you could possibily get JOTM to work for you. There are some papers that detail getting it to work with Tomcat which may provides the details need for you situation. First ask yourself if you really need 2PC. Its a world of hurt to get going and keep going. Also it carries a performance hit which all adds up to not bothering.


Top
 Profile  
 
 Post subject: JTA transaction manager
PostPosted: Mon Dec 15, 2003 1:02 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
It's quite likely I don't understand the various JTA components and the roles they play (speaking of which, can anyone recommend a good place to go to learn more about JTA... I'm not impressed with Sun's docs).

It was my impression that WebLogic provides the JTA transaction manager, and that I simply needed to configure Hibernate to use it. As I said, if I change the Hibernate connection settings to use the WebLogic-managed DataSource, things work fine. What does it mean to manage the DataSource... I thought that was just meant managing the Connection pool.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not sure if I can explain it all that well but I will have a go:
The database pool can be a Transaction aware resource that can be managed. 1PC (One Phase Commit) is simple and fast where the manager starts the transaction on the single datasource and then commit or rollback that resource appropriately.
The transaction manager can be your program (Straight JDBC) or an external provider such as JTA. There is a relationship between the manager and the resource so that the transaction boundaries can occur. You program can control the transaction boundaries (Straight JDBC or manual JTA calls [user transactions - sometimes call client transactions]). Alternatively, the transcation boundaries are controlled by a container, eg CMT. The transaction manager or container needs to have knowledge of the transaction resource to perform the operations correctly.
2PC (Two Phase Commit) allows multiple transaction resources to be co-ordinated. All transaction resource must commit for a final commit to be performed. If one of the resource rollbacks then all resources are rolled back. The are other states (usually related to being unable to perform the operation) but what needs to be understood is the the commit and rollback functions on a resource are forwarded to the Transaction co-ordinator to perform the actual commit on each resource involved in the transaction.
The first phase equates to a vote then the XA transaction co-ordinator acts appriopriately when all the votes are in which is the 2nd Phase. Obviously, there is overhead in managing the protocol and a relationship between the transaction resources, manager and co-ordinator.
Unless you need 2PC don't use it - its just more plumbing that costs and can go wrong. I hope this is clear enough.


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Tue Dec 16, 2003 12:38 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Thanks -- that was informative and backed up most of my understanding. I am hoping to avoid JTA and 2PC at this point: although in theory it would be magnificent, we want to keep our application architecture as simple as possible for as long as possible. Just requiring an EJB container to run units tests, for example, is a change that we don't want to make until it's really warranted.

Cheers,
Nate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 7:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Some/Bulk or the Testing outside of a container is usefull. A current project I am working on used CMT in SLSBs but most of the work is done is DAOs so I can test the hierarchiy outside of the CMT environment as I provide a Transaction co-ordinator (based on JDBC connection) that does the work.
If these tests pass then some testing occurs in container to make sure all is OK in the production like environment. I get the best of both worlds (as well as not required to use a SLSB if its decided to not use EJBs at all).


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