Nick's Tech Blog: hibernate

Pages

Showing posts with label hibernate. Show all posts
Showing posts with label hibernate. Show all posts

Thursday, June 9, 2011

java.lang.NoSuchMethodException: com.ibm.ejs.j2c.DefaultSecurityHelper

Problem

Received the following exceptions from Websphere7.

Caused by: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
[Root exception is java.lang.NoSuchMethodException: com.ibm.ejs.j2c.DefaultSecurityHelper.(javax.resource.spi.ManagedConnectionFactory, com.ibm.ejs.j2c.MCFExtendedProperties)]

Caused by: java.lang.NoSuchMethodException: com.ibm.ejs.j2c.DefaultSecurityHelper.(javax.resource.spi.ManagedConnectionFactory, com.ibm.ejs.j2c.MCFExtendedProperties)


Solution

I'm not sure if one (or a combination of both) solutions fixed the issue, but here they are.

A) Remove any "connection-api" dependencies from the application.
See: https://forum.hibernate.org/viewtopic.php?t=189&view=previous&sid=13f603a429a675f5d397059b237952df

B) The application is trying to use an XA datasource, but the driver (.jar file) doesn't support it. Check the datasource is using the correct libraries.
See: http://www.ibm.com/developerworks/forums/thread.jspa?threadID=109582

java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider

Problem

Received the following stacktrace from Websphere7.

Caused by: java.lang.ClassCastException: com.ibm.websphere.persistence.PersistenceProviderImpl incompatible with javax.persistence.spi.PersistenceProvider
        at javax.persistence.Persistence$1.isLoaded(Persistence.java:77)
        at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)
        at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:94)
        at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
        at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:757)
        ... 77 more



Solution

  1. Remove hibernate-jpa-2.0-api-1.0.0.Final.jar from your war file, and add it as a shared library to your application. 
  2. Make sure you restart your application.
N.B. You shouldn't need to do this if you've setup the shared library correctly, but if you're still having trouble, it might help if you have the following classloading strategy enabled - Classes loaded with local class loader first (parent last)

See:
Configuring persistence provider support in the application server - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/tejb_configpp.html
Creating shared libraries - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/tcws_sharedlib_create.html
Associating shared libraries with applications or modules - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.zseries.doc/info/zseries/ae/tcws_sharedlib_app.html
Configuring class loaders of a server - http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/trun_classload_server.html

Caused by: org.hibernate.HibernateException: Could not obtain WebSphere TransactionManager

Problem

Received the following stacktrace from Websphere7.

Caused by: org.hibernate.HibernateException: Could not obtain WebSphere TransactionManager
(Stack trace removed...)
Caused by: java.lang.ClassCastException: com.ibm.ws.tx.jta.TranManagerSet incompatible with javax.transaction.TransactionManager


Solution

Make sure you have the following transaction manager lookup class in your persistence.xml.

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

See: http://lockdog.wordpress.com/2009/09/07/6/ (May require Google translate)