-->
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.  [ 3 posts ] 
Author Message
 Post subject: Getting error: Could not locate TransactionManager
PostPosted: Fri Aug 10, 2007 3:21 am 
Newbie

Joined: Fri Aug 10, 2007 2:04 am
Posts: 7
Hi there,
After reading the following link :
Read this: http://hibernate.org/42.html
Code:


I am trying to use JTA's UserTransaction interface for transaction demarcation.
When my JunitTest class PatientTest calls getNextPatient() method of my business logic class PatientManager, it gets the error
org.hibernate.HibernateException: Could not locate TransactionManager

I would appreciate some help in resolving this issue,

Hibernate version:3.2.4 SP1
App Server version:JBoss-4.2.1GA
Name and version of the database : PostgreSQL 8.1

Here's my Hibernate.cfg.xml
Hibernate.cfg.xml

http://rafb.net/p/XpwAFE18.html

Acc. to reference docs, section 3.8.2,

http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html#configuration-optional-jndi

I am using the following property
for automatic JNDI binding of sessionFactory. But I have not configured anything explicitly on the server side. Is that okay ?

Code:
<property name="hibernate.session_factory_name">
      java:hibernate/SessionFactory
</property>


Similarly, I have taken this property from section 3.7 (haven't configured anything explicitly on the server side )

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


For property,

Code:
<property name="hibernate.connection.datasource">
         postgresDS
      </property>


For this one, i have done the required setup on the server side.
I have dropped my postgres-ds.xml file in <jboss-install-dir>\\server\default\deploy folder with following contents
http://rafb.net/p/4x761u63.html

A separately written unit-test that looks up this datasource as

Code:
InitialContext ic = new InitialContext();
DataSource ds=(DataSource) ic.lookup("postgresDS");


is working fine. So datasource settings are fine in this case.


Here's my JunitTest class - named PatientTest.java
http://rafb.net/p/XeCRbb39.html

Here's my businessObject class - named PatientManager.java
http://rafb.net/p/n30BBc18.html

Full stack trace of any exception that occurs:
http://rafb.net/p/U3pl8Q32.html

Debug level Hibernate log excerpt:
http://rafb.net/p/stjSz681.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 6:05 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Hi,
check the following link to see how to do the configuration:

http://www.jboss.org/?module=bb&op=viewtopic&t=70614


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 12:09 pm 
Newbie

Joined: Fri Aug 10, 2007 2:04 am
Posts: 7
thanks for the reply mkarami.
I am using Core Hibernate (instead of EJB3) with JTA (from jboss App server).
Secondly, if i look close when dunks reported this problem,
Code:
org.hibernate.HibernateException: Could not locate TransactionManager


his settings were similar as mine which were

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



The solution to this problem posted by jacekolszak was to have this code piece

Quote:
EJB3StandaloneBootstrap.boot(null);

deployer = new EJB3StandaloneDeployer();
deployer.setJndiProperties(getInitialContextProperties());
deployer.create();
deployer.start();
ctx = getInitialContext();
.
.
.
public static InitialContext getInitialContext() throws Exception {
Hashtable props = getInitialContextProperties();
return new InitialContext(props);
}

private static Hashtable getInitialContextProperties() {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("java.naming.factory.initial",
"org.jnp.interfaces.LocalOnlyContextFactory");
props.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
return props;
}


I am not sure how I can setup these initialContextProperties correctly when working with core Hibernate, I gave it a shot to get as close as possible. But I am still getting the same exact error and debug outputs.

Here's my latest Patient Manager
http://rafb.net/p/mQWNAq93.html

The only change I have done is this code block
Code:
UserTransaction utx=null;
   Context ctx=null;
   public PatientManager() throws Exception{
      Configuration conf = new Configuration();
      conf.setProperties(getInitialContextProperties());
      utx= (UserTransaction) getInitialContext().lookup("java:comp/UserTransaction");
   }
   public static InitialContext getInitialContext() throws Exception {
      Hashtable props = getInitialContextProperties();
      return new InitialContext(props);
      }

      private static Properties getInitialContextProperties() {
      Properties props = new Properties();
      props.put("java.naming.factory.initial",
      "org.jnp.interfaces.LocalOnlyContextFactory");
      props.put("java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");
      return props;
   }


it uses Configuration object instead of EJB3StandaloneDeployer(I am assuming they are each other's equivalents in Hibernate core and EJb3 worlds)

My PatientTest and hibernate.cfg.xml stay the same.
Here's my Hibernate.cfg.xml

http://rafb.net/p/XpwAFE18.html

Here's the PatientTest
http://rafb.net/p/XeCRbb39.html


I notice I get this exception in my HibernateUtil class's static block..
Here's my HibernateUtil
http://rafb.net/p/s6XFlj76.html

Here's the exception trace again
http://rafb.net/p/0PyMuw56.html

Here's the DEBUG output again..
http://rafb.net/p/wK5Hdn55.html

I don't know why, please help ...


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