-->
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: WebSphere 7 - Session injection problem
PostPosted: Mon Feb 02, 2009 5:49 am 
Newbie

Joined: Fri Jan 30, 2009 4:58 pm
Posts: 6
Upon initialization of a SLSB in WebSphere 7.0 I get the following exception:

Code:
[2.2.09 10:33:04:828 CET] 00000013 BusinessExcep E   CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "ping". Exception data: javax.ejb.EJBException: Injection failure; nested exception is: java.lang.IllegalArgumentException: Can not set org.hibernate.Session field beans.TestBeanEJB.session to com.ibm.ws.jpa.management.JPATxEntityManager
java.lang.IllegalArgumentException: Can not set org.hibernate.Session field beans.TestBeanEJB.session to com.ibm.ws.jpa.management.JPATxEntityManager
   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:158)
   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:162)
   at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)
   at java.lang.reflect.Field.set(Field.java:659)
   at com.ibm.wsspi.injectionengine.InjectionTargetField.inject(InjectionTargetField.java:253)
   at com.ibm.ws.injectionengine.InjectionEngineImpl.inject(InjectionEngineImpl.java:579)
   at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:316)
   at com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:45)
   at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1028)
   at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1138)
   at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:84)
   at com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:599)
   at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3956)
   at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3341)
   at beans.EJSRemote0SLTestBeanEJB_505e9ee2.ping(EJSRemote0SLTestBeanEJB_505e9ee2.java)
   at beans._EJSRemote0SLTestBeanEJB_505e9ee2_Tie.ping(_EJSRemote0SLTestBeanEJB_505e9ee2_Tie.java)
   at beans._EJSRemote0SLTestBeanEJB_505e9ee2_Tie._invoke(_EJSRemote0SLTestBeanEJB_505e9ee2_Tie.java)
   at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
   at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
   at com.ibm.rmi.iiop.ORB.process(ORB.java:504)
   at com.ibm.CORBA.iiop.ORB.process(ORB.java:1573)
   at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2793)
   at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2662)
   at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
   at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)



The bean looks like:

Code:
@Stateless
@Remote
public class TestBeanEJB implements TestBean {
    @PersistenceContext(unitName = "Test")
    private Session session;

    public String ping() {
        return "pong";
    }
}


my persistence.xml looks like:

Code:
<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/persistence_1_0.xsd"
             version="1.0">
    <persistence-unit name="Test">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/MyDS</jta-data-source>
        <properties>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>

            <!-- WebSphere transaction manager lookup class -->
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
        </properties>
    </persistence-unit>
</persistence>

The application is packed as an ear with an ejb-jar containing the bean. There are no exceptions during application installation/startup and Hibernate initializes without any errors.

I'm using WebSphere 7.0 + Fix pack 1.

Why does the injection engine try to inject a JPATxEntityManager and not a Hibernate session here?

Regards,
Magnus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 7:30 am 
Newbie

Joined: Fri Jan 30, 2009 4:58 pm
Posts: 6
Changing from

Code:
@PersistenceContext(unitName = "Test")
private Session session;

to

Code:
@PersistenceContext(unitName = "Test")
private EntityManager session;

makes the injection work and I can see that Hibernate is used as JPA provider. However, the code base I'm trying to port from JBossAS to WAS 7.0 heavily relies on injection of Hibernate sessions. How can I make the Session injection work in my SLSB on WAS 7.0?


Regards,
Magnus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 7:38 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You can get the underlying hibernate session via
Code:
(Session)entityManager.getDelegate()

_________________
-----------------
Need advanced help? http://www.viada.eu


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.