Nick's Tech Blog: jpa2

Pages

Showing posts with label jpa2. Show all posts
Showing posts with label jpa2. Show all posts

Tuesday, June 14, 2011

Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil

Problem

Received the following stacktrace from Websphere7.

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]
: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax.persistence.spi.ProviderUtil
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:939)
... 50 more
Caused by: java.lang.NoClassDefFoundError: javax.persistence.spi.ProviderUtil
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:72)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:134)
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.(HibernateJpaVendorAdapter.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:56)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:39)
at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
... 52 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.ProviderUtil
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:653)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:509)
at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:509)
at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
... 61 more


Basically, it's complaining that JPA2 libraries aren't installed.
       
Solution
  1. Stop the Websphere7 server.
  2. Install "OSGi Applications and Java Persistence API (JPA) 2.0 feature pack" using "IBM Installation Manager"
    1. http://www-01.ibm.com/software/webservers/appserv/was/featurepacks/osgi/instopt/index.html
  3. At the last step of the installation, select "Open Profile Management Tool"
  4. From the "Profile Management Tool 7.0" window...
  5. Go to the "Profile Management Tool" tab
  6. Select the relevant profile.
  7. Select "Augment..."
  8. At "Select the augment to apply to the selected profile", select "Application server with Java Persistence API 2.0 feature"
  9. Apply, then Exit the tool.
  10. Start up the Websphere7 server.

Additional Notes

Problem: The Installation Manager does not synchronize with WebSphere Application Server if WebSphere Application Server is at higher fix pack level than recommended for the feature pack.

Solution: Download the latest version of WebSphere Application Server import repositories and add it to the Installation Manager:
http://public.dhe.ibm.com/software/websphere/downloads/was/import/

Thursday, June 9, 2011

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)