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: Configuring Hibernate to use BMP
PostPosted: Mon Jul 23, 2007 2:01 pm 
Newbie

Joined: Tue Mar 21, 2006 1:28 pm
Posts: 2
Hi guys



I am using
Hibernate 3.0
MS SQL Server 2000
RAD Version: 7.0.0
The WebSphere 6.1 is not standalone, it comes with RAD 7 !!!

I am trying to configure Hibernate in non-managed environment which is to use JTA in BMP environment.
I do realize that using the JTATransactionFactory would prvide for me as the Book [Java Persistence with Hibernate ] says (page 99) :
The JTATransactionFactory enables correct session scoping and propagation for JTA if you decide to use
SessionFactory.getCurrentSession() method


This is the hibernate.cfg.xml

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=db1</property>
        <property name="connection.username">user1</property>
        <property name="connection.password">password</property>       
             
       <!--  bean-managed transaction  -->
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property      
<property name="hibernate.transaction.maneger_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
       <property name="jta.UserTransaction">java:comp/UserTransaction</property>
</session-factory>
</hibernate-configuration>


Here is the code inside Stateless Session Bean
I am trying to run
Code:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:2809/");
      
Context ic = new InitialContext(env);
configuration = new Configuration().configure(someURL);

sessionFactory = configuration.buildSessionFactory();
// the following line causes error
Session session = (Session) sessionFactory.getCurrentSession();


The error occurs when I am attempting to get current session which is supposed to be associated with UserTransaction.
here is the error I get

Code:
DEBUG [P=392992:O=0:CT] (SessionImpl.java:220) - opened session at timestamp: 11852124398
DEBUG [P=392992:O=0:CT] (JTATransaction.java:57) - Looking for UserTransaction under: java:comp/UserTransaction
ERROR [P=392992:O=0:CT] (JTATransaction.java:63) - Could not find UserTransaction in JNDI
javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".
   at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1095)
   at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:991)
   at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
   at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
   at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:204)
   at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:144)
   at javax.naming.InitialContext.lookup(InitialContext.java:363)
   at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
   at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:57)
   at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:193)
   at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1315)
   at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78)
   at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
   at Main.jtaTest1(Main.java)
   at Main.main(Main.java)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:615)
   at com.ibm.ws.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:747)
   at com.ibm.ws.client.applicationclient.launchClient.main(launchClient.java:469)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:615)
   at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:183)
   at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:90)
   at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:72)
   at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:615)
   at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
   at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
   at org.eclipse.core.launcher.Main.run(Main.java:973)
   at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:264)
   at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:75)

I am wondering:
1. If this error occurs because I am trying to run this code in WAS 6.1 that comes with RAD ?
2. Do I need to run this code in Session Bean ONLY ?

Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 23, 2007 4:35 pm 
Newbie

Joined: Tue Mar 21, 2006 1:28 pm
Posts: 2
Found solution :
1. Set current_session_context_class to be jta
<property name="current_session_context_class">jta</property>
2. Fixed the misspeled hibernate.transaction.manager_lookup_class
( was hibernate.transaction.maneger_lookup_class )
3. added websphere ext jar to get the
com.ibm.websphere.jtaextensions.SynchronizationCallback


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.