-->
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.  [ 6 posts ] 
Author Message
 Post subject: Has anyone used JPA inside WebSphere AS 6.1?
PostPosted: Wed Dec 13, 2006 2:56 pm 
Newbie

Joined: Wed Dec 13, 2006 2:48 pm
Posts: 1
IBM WebSphere 6.1 is J2EE 1.4 and jdk 1.5. I am using JPA successfully in JBoss 4.0.4 environment. Having problems in WAS 6.1
Garth


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 6:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes, I know some customers are using Hibernate EM successfully on Websphere 6.1

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 2:28 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
Hi Garth,

We deploy and run successfully EJB JPA with Hibernate 3.2.1 applications in WebSphere 6.1 (applications generated by OpenXava).

Think that WebSphere datasources do not behave as JBoss datasources.

Do you use JPA api inside JSPs ?

Cheers
Javier Paniza


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 4:22 pm 
Newbie

Joined: Wed Jan 31, 2007 5:02 am
Posts: 6
Hi Garth,


have you deployed successfully EJB JPA with Hibernate 3.2.1 applications in WebSphere 6.1 yet ?!!

I'am relatively new to hibernate and WebSphere but have to migrate a time critical project with EM/JPA-hibernate from JBoss to WebSphere 6.1 / CMT.
I have problems to find out the right configuration properties for persistence.xml and so on. Could you give me some short configuration / programming hints to run under above mentioned constellation ??


Especially handling of transaction boundaries and flushing seem to be problematic.
At the bottom you see my persistence.xml and an adapted HibernateUtil class to get the EntityManager.

Thanks a lot,
Tom



Code:
   <persistence-unit name="rcl-test" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>jdbc/MyDataSource</jta-data-source>
      <properties>
         <property name="hibernate.archive.autodetection" value="class, hbm"/>
         
           <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
           <property name="hibernate.show_sql" value="true"/>
           <!--property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/-->
           <property name="hibernate.session_factory_name" value="MyProject/SessionFactory"/>

           <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
           <property name="hibernate.jdni.class" value="com.ibm.websphere.naming.WsnInitialContextFactory"/>
           <property name="hibernate.jdni.url" value="iiop://localhost:2809/"/>
           
      </properties>
   </persistence-unit>




Code:
public class JpaUtil {

    private static Log log = LogFactory.getLog(JpaUtil.class);

    private static Map<String, EntityManagerFactory> factories = new HashMap<String, EntityManagerFactory>();

    /**
     * Returns the Entity manager to use.
     *
     * @return Configuration
     */
    public static EntityManager getEntityManager(String persistenceUnit) {
       return getEntityManager(persistenceUnit, new HashMap());
    }
   
    public static EntityManager getEntityManager(String persistenceUnit, Map overwrite) {
      log.info("get entity manager for unit: " + persistenceUnit);
       EntityManagerFactory emf = factories.get(persistenceUnit);
       if (emf == null) {
          log.info("    create NEW manager");
          emf = Persistence.createEntityManagerFactory(persistenceUnit, overwrite);
          factories.put(persistenceUnit, emf);
       }
       else {
          log.info("    found CACHED manager");
       }
      EntityManager manager = emf.createEntityManager();
      manager.setFlushMode(FlushModeType.AUTO);

        return manager;
    }


Top
 Profile  
 
 Post subject: Has anyone used JPA inside WebSphere AS 6.1?
PostPosted: Wed Feb 14, 2007 2:57 am 
Newbie

Joined: Tue Feb 14, 2006 6:53 am
Posts: 7
WebSphere 6.1
WebSphere DataSources and TransactionManager
DB2 V8

Create the EntityManager and store it on ThreadLocal just after the entry point which is a stateless session bean with transaction type = required. Close the EntityManager before leaving the EJB.

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd" version="1.0">

<persistence-unit name="persistence" transaction-type="JTA">

<jta-data-source>java:comp/env/Hiber DataSource</jta-data-source>

<class>xxx.xxx.test.entity.Contact</class>
<class>xxx.xxx.test.entity.Phone</class>
<class>xxx.xxx.test.entity.Bid</class>

<properties>

<property name="hibernate.archive.autodetection" value="none"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>


<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>

<property name="hibernate.cache.use_second_level_cache" value="false"/>

</properties>

</persistence-unit>

</persistence>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 9:50 am 
Newbie

Joined: Wed Jan 31, 2007 5:02 am
Posts: 6
Hi Lindavr,

thanks for your @annotations ;-)

Your suggestion to use ThreadLocal works fine in single ejb context. If one have a service calling (local/remote) service context this dos'nt work.

I have other problems with EM/JPA with hibernate 3.2 and CMT under WAS 6.1 currently. All works fine under the so called "universal test client" of IBM's AST - IDE testing method by method. But if one wants to call the services remotely by an application client (launcher) i got a "javax.naming.NameNotFoundException" raised by the "WebSphereExtendedJTATransactionLookup" class (see below).

Uncommenting the "hibernate.transaction.factory_class" property of my persistence.xml file (see my previous posting) this seems to solve my problem. But i got hibernate warnings in my logfiles like:

hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation

org.hibernate.ejb.AbstractEntityManagerImpl joinTransaction - Cannot join transaction, not a JoinableCMTTransaction


On the other way I saw my EntityManager obtaining the Hibernate Session by an "openSession" call. I read hints, that in CMT environments "getCurrentSession" must be called.

Are there other EntityManager[Factory] implementations i have to use than the standard ones?

Are there any other issues how to configure EM hibernate 3.2 with CMT WAS 6.1 ??!!!

Thanks a lot, Tom


Code:
javax.naming.ConfigurationException [Root exception is javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".]
   at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:411)
   at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:388)
   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.MyWebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:118)
   at org.hibernate.transaction.MyWebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(MyWebSphereExtendedJTATransactionLookup.java:115)
   at org.hibernate.transaction.MyWebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getTransaction(MyWebSphereExtendedJTATransactionLookup.java:85)
   at org.hibernate.transaction.CMTTransaction.getTransaction(CMTTransaction.java:91)
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:489)
   at org.hibernate.transaction.MyWebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter$1.invoke(MyWebSphereExtendedJTATransactionLookup.java:139)
   at $Proxy15.beforeCompletion(Unknown Source)
   at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65)
   at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:240)
   at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2373)
   at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1606)
   at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1577)
   at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1512)
   at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:237)
   at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:162)
   at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:756)
   at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:181)
   at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:581)
   at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:3893)
   at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:3715)
   at de.ivu.mb.rcl.proto.waswrapper.service.imported.EJSRemoteStatelessRclCompFacade_5284fa46.findEinsatzplanVOAtBetrieb(EJSRemoteStatelessRclCompFacade_5284fa46.java:534)
   at de.ivu.mb.rcl.proto.waswrapper.service.imported._EJSRemoteStatelessRclCompFacade_5284fa46_Tie.findEinsatzplanVOAtBetrieb(_EJSRemoteStatelessRclCompFacade_5284fa46_Tie.java:240)
   at de.ivu.mb.rcl.proto.waswrapper.service.imported._EJSRemoteStatelessRclCompFacade_5284fa46_Tie._invoke(_EJSRemoteStatelessRclCompFacade_5284fa46_Tie.java:144)
   at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:613)
   at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:466)
   at com.ibm.rmi.iiop.ORB.process(ORB.java:503)
   at com.ibm.CORBA.iiop.ORB.process(ORB.java:1553)
   at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2680)
   at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2554)
   at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:62)
   at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".
   at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1767)
   at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1083)
   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)
   ... 35 more


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