-->
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 wiht JTA transaction
PostPosted: Wed Feb 06, 2008 7:59 am 
Newbie

Joined: Mon Jan 28, 2008 1:55 am
Posts: 8
hi all.

im devoloping a simple standalone hibernate application. I want to use jta transaction.

here is my hibernate.cfg.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/test_jta</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="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>

<property name="hbm2ddl.auto">create</property>

<mapping resource="dev/Student.hbm.xml"/>


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


and this is the error im getting

[java] INFO: cleaning up connection pool: jdbc:mysql://localhost:3306/test_jta
[java] Feb 6, 2008 5:08:12 PM org.hibernate.util.NamingHelper getInitialContext
[java] INFO: JNDI InitialContext properties:{}
[java] ***********Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not locate TransactionManager
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at dev.StudentManager.addStudent(Unknown Source)
[java] at dev.StudentManager.main(Unknown Source)
[java] Caused by: org.hibernate.HibernateException: Could not locate TransactionManager
[java] at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:257)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
[java] ... 3 more
[java] Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
[java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
[java] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
[java] at javax.naming.InitialContext.lookup(InitialContext.java:392)
[java] at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
[java] ... 5 more
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 11 seconds

this is the HibernateUtil class

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xm
sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("***********Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {

return sessionFactory;
}

}

when i remove Properties regarding JTA transaction from hibernate.cfg.xml file then
program is working. As i understood problem is with creating JTA transaction within
session factory.
if any one can solve this please reply me. thanks.

wijitha


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 4:35 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
If this is truly a standalone app, then you'll have to create your own JTA integration with some JTA transaction manager. This isn't really practical today. You certainly won't get any mileage out of specifying a factory+lookup since you're not deploying inside an appserver.

If you're actually using JBoss, then your config looks good, but the app isn't standalone :)

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.