-->
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: Hibernate using JTA
PostPosted: Thu Jan 31, 2008 2:35 am 
Newbie

Joined: Mon Jan 28, 2008 1:55 am
Posts: 8
hi all
im new to hibernate and i am using JTA transaction.
this is my hibernate.hbm.xml.

<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bank_ex</property>
<property name="connection.username">root</property>
<property name="connection.password">wijithaw</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JNDITransactionManagerLookup</property>



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


<!--<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>-->
<property name="hbm2ddl.auto">create</property>

<mapping resource="dev/Account.hbm.xml"/>
<mapping resource="dev/Customer.hbm.xml"/>

</session-factory>
</hibernate-configuration>


java code is

Session session = HibernateUtil.getSessionFactory().openSession();
UserTransaction tx = null;
try {

tx = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
Account account = (Account) session.load(Account.class, accountNum);
account.withdraw(amount);
tx.commit();
} catch (RuntimeException e) {
//To change body of catch statement use File | Settings | File Templates.
tx.rollback();
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error Message :"+e.getMessage()+".\n");
} finally {
session.close();
}

this is the error im getting.

[java] Jan 31, 2008 11:49:45 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
[java] INFO: instantiating TransactionManagerLookup: org.hibernate.transaction.JNDITransactionManagerLookup
[java] Jan 31, 2008 11:49:45 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
[java] SEVERE: Could not instantiate TransactionManagerLookup
[java] java.lang.InstantiationException
[java] at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
[java] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[java] at java.lang.Class.newInstance0(Class.java:355)
[java] at java.lang.Class.newInstance(Class.java:308)
[java] at org.hibernate.transaction.TransactionManagerLookupFactory.getTransactionManagerLookup(TransactionManagerLookupFactory.java:41)
[java] at org.hibernate.cfg.SettingsFactory.createTransactionManagerLookup(SettingsFactory.java:309)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:174)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at dev.BankManager.storeCustomer(Unknown Source)
[java] at dev.BankManager.createCustomer(Unknown Source)
[java] at dev.BankManager.addAccount(Unknown Source)
[java] at dev.BankRannable.run(Unknown Source)
[java] at dev.BankManager.main(Unknown Source)
[java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not instantiate TransactionManagerLookup
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at dev.BankManager.storeCustomer(Unknown Source)
[java] at dev.BankManager.createCustomer(Unknown Source)
[java] at dev.BankManager.addAccount(Unknown Source)
[java] at dev.BankRannable.run(Unknown Source)
[java] at dev.BankManager.main(Unknown Source)
[java] Caused by: org.hibernate.HibernateException: Could not instantiate TransactionManagerLookup
[java] at org.hibernate.transaction.TransactionManagerLookupFactory.getTransactionManagerLookup(TransactionManagerLookupFactory.java:47)
[java] at org.hibernate.cfg.SettingsFactory.createTransactionManagerLookup(SettingsFactory.java:309)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:174)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
[java] ... 6 more
[java] Java Result: 1



can any one tell me what are the steps to follow to use JTA trasaction.

if u can help me please reply me.
thanks.

wijitha


Top
 Profile  
 
 Post subject: Re: Hibernate using JTA
PostPosted: Thu Jan 31, 2008 10:00 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
The first problem in your mapping is that you are using hibernate's connection pool with a JTA transaction manager. JTA is a global transaction manager and hibernate's connection pool is local to hibernate. I am not aware if hibernate is actually synchronizing this with global transactions. Second you are getting a user transaction but you are not starting it.

Take a look at this post. It should give you an idea how to setup a JTA transaction environment:

http://forum.hibernate.org/viewtopic.ph ... highlight=



Farzad-


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.