-->
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.  [ 9 posts ] 
Author Message
 Post subject: OC4J, CMT, UserTransaction
PostPosted: Mon Sep 05, 2005 5:22 pm 
Newbie

Joined: Wed Feb 04, 2004 7:12 am
Posts: 18
Location: Brasilia - Brazil
Hi,

There is a trouble related to Hibernate in the following situation:
- When it runs on OC4J (10g 10.1.2.0.0);
- It uses EJB + CMT;

My hibernate.cfg.xml:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory name="java:hibernate/SessionFactory">
      <property name="connection.datasource">java:comp/env/jdbc/BancoDS</property>
      <property name="show_sql">false</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="use_outer_join">true</property>
      <property name="hibernate.cache.use_query_cache">true</property>
     
      <property name="hibernate.connection.release_mode">auto</property>
      <property name="hibernate.transaction.auto_close_session">true</property>
      <property name="hibernate.transaction.flush_before_completion">true</property>
      <property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
      <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.OrionTransactionManagerLookup</property>

      <mapping resource="Account.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


My code:

Code:
(...)
public void save(Account acc)
{
    Session s = sessionFactory.getCurrentSession();
    s.save(acc);
}
(...)


Error message:

Code:
org.hibernate.HibernateException: Could not locate TransactionManager
        at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.jav
a:26)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:270)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
(...)
Caused by: javax.naming.NameNotFoundException: Only session and message-driven beans with bean-managed transaction are a
llowed to use UserTransaction


When this error happens? On SessionFactory initilization:

Code:
(...)
     try
        {
            sessionFactory = new Configuration().configure()
                    .buildSessionFactory();
        }
        catch (Throwable ex)
        {
            throw new ExceptionInInitializerError(ex);
        }
(...)


Reading specification on item J2EE.5.6

UserTransaction References

Certain J2EE application component types are allowed to use the JTA UserTransaction interface to start, commit, and abort transactions. Such application components can find an appropriate object implementing the UserTransaction interface by looking up the JNDI name java:comp/ UserTransaction. The container is only required to provide the java:comp/UserTransaction name for those components that can validly make use of it. Any such reference to a UserTransaction object is only valid within the component instance that performed the lookup. See the individual component definitions for further information.
The following example illustrates how an application component acquires and uses a UserTransaction object.


We can suggest that OC4J is throwing an exception when SessionFactory tries to lookup the UserTransaction, because EJB is marked as CMT (see red letters).

If I use org.hibernate.transaction.JDBCTransactionFactory as my transaction.factory_class it works well and it's possible to call multiple CMT EJB under same transaction, but I have to flush() everytime I change an object, making performance worse than flushing on commit.

Using JDBCTransactionFactory, I'll loose every resource related to JTA:
- hibernate.transaction.auto_close_session
- hibernate.transaction.flush_before_completion

The thing is that everything is running well, but it should be better if I could integrate Hibernate to OC4J (and spec) TransactionManager. Isn't it a problem if every Application Server decides to work as OC4J (and possibly WebSphere) works? Throwing an exception when some CMT EJB tries to lookup an UserTransaction? Or worse than this, Hibernate is using something optional?

_________________
___________________________
[ MediaSonic (www.geleira.org) ]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 6:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The problem is that Orion seems to provide access to the TransactionManager through the UserTransaction JNDI lookup mechanism. The only thing you can do is find a way to access the TransactionManager without UserTransaction. Looking up the TransactionManager is not defined by the specification, so every vendor has his own crude mechanism to do this. That's why you need a OrionLookup class in the first place.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 6:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And, by the way, the configuration property is named "hibernate.transaction.factory_class".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 6:54 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Finally, I've recently been working on a Hibernate application on OAS 10g and I did not have this problem with the forbidden lookup. I don't know enough about Orion, so maybe there is a switch somewhere to make it more friendly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 7:09 pm 
Newbie

Joined: Wed Feb 04, 2004 7:12 am
Posts: 18
Location: Brasilia - Brazil
christian wrote:
And, by the way, the configuration property is named "hibernate.transaction.factory_class".


Yes, that's the problem, I was looking for a way to get a TransactionManager instance, but unsucessfull. As I read, Weblogic register it as "javax.jta.TransactionManager" in its JNDI namespace, but I think OC4J doesn't provide those resource.

It's necessary to get a TransactionManager instance because Hibernate register itself as a transaction event listener (TransactionManager.getTransaction().registerSynchronization(Synchronization sync))?

I'll be looking for a solution, but I have no much hope for that. :-(

Thank you for the answer.

_________________
___________________________
[ MediaSonic (www.geleira.org) ]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 7:43 pm 
Newbie

Joined: Wed Feb 04, 2004 7:12 am
Posts: 18
Location: Brasilia - Brazil
christian wrote:
Finally, I've recently been working on a Hibernate application on OAS 10g and I did not have this problem with the forbidden lookup. I don't know enough about Orion, so maybe there is a switch somewhere to make it more friendly.


As I know, this problem didn't happen with previous versions of OC4J, but the latest one (10.2.1.0) is not allowing to lookup UserTransaction.

Would you like to send your sample application? I can test it in my enviroment and send the results. After that I'll write a documentation to solve this problem or confirm the theory about the new version of OC4J.

Thanks a lot.

_________________
___________________________
[ MediaSonic (www.geleira.org) ]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 7:52 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uh, sorry, I only touch commercial appservers for money. But if you figure out how to do it, please submit a patch to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:19 pm 
Newbie

Joined: Wed Feb 04, 2004 7:12 am
Posts: 18
Location: Brasilia - Brazil
christian wrote:
Uh, sorry, I only touch commercial appservers for money. But if you figure out how to do it, please submit a patch to JIRA.


Yeah! :-) Off course, you're allright, but can you tell me what was the version you've tested?

If I found the solution (I'm still have a little hope :), I'll send the patch, for sure!

Thanks a lot and this is the last question (at least for today) :)

_________________
___________________________
[ MediaSonic (www.geleira.org) ]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't know the exact version.


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