Nick's Tech Blog: websphere7

Pages

Showing posts with label websphere7. Show all posts
Showing posts with label websphere7. 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

No HttpSession currently exists

Problem

I was unable to log into the web application, despite correct login details. Received a "No HttpSession currently exists" message in the web filters, despite successful SessionContext creation (previously in the logs).

e.g.
SecurityContextHolder now cleared, as request processing completed
An Authentication object was not found in the SecurityContext


Solution

It appeared as though Websphere7 wasn't saving the session (or anything in it).

By setting a custom session id in the cookies, and by giving the cookies a context path, I was able to get the sessions working (with an app restart).

See: WebSphere Application Server V7: Session Management - http://www.redbooks.ibm.com/redpapers/pdfs/redp4580.pdf

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

java.lang.VerifyError: com/ibm/websphere/uow/UOWSynchronizationRegistry.registerInterposedSynchronization(Ljavax/transaction/Synchronization;)V

Problem

Received the following stacktrace from Websphere7.

Caused by: java.lang.VerifyError: com/ibm/websphere/uow/UOWSynchronizationRegistry.registerInterposedSynchronization(Ljavax/transaction/Synchronization;)V
        at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:355)
        at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:1067)
        ... 97 more


Solution

Remove the jta.jar from the dependencies in the war file.

java.lang.IncompatibleClassChangeError

Problem

Received the following stacktrace from Websphere7.

[7/06/11 15:34:25:185 EST] 00000011 webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[/WEB-INF/views/500.jsp]: java.lang.IncompatibleClassChangeError
        at org.apache.taglibs.standard.tlv.JstlCoreTLV$Handler.startElement(JstlCoreTLV.java:250)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
        at javax.xml.parsers.SAXParser.parse(Unknown Source)
        at org.apache.taglibs.standard.tlv.JstlBaseTLV.validate(JstlBaseTLV.java:156)
        at org.apache.taglibs.standard.tlv.JstlCoreTLV.validate(JstlCoreTLV.java:96)


Solution

Make sure the following (latest if possible) xml apis are used (and excluded from other dependencies).

        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.1</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.3.04</version>
        </dependency>


See: http://maven.40175.n5.nabble.com/m2-IncompatibleClassChangeError-using-maven-surefire-plugin-2-1-3-td61403.html

Websphere7 > null mapping for filter

Problem

Received the following error from Websphere7.

[7/06/11 12:48:47:093 EST] 0000001e filter W com.ibm.ws.webcontainer.filter.WebAppFilterManager getFilterChainContents SRVE0307W: null mapping for filter. This may occur if you try to specify a * mapping on a pre-2.5 app.
[7/06/11 12:48:47:124 EST] 0000001e webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[/WEB-INF/views/500.jsp]: java.lang.IncompatibleClassChangeError



Solution

Go to the application installation path under Websphere. e.g.
%was_home%\AppServer\profiles\AppSrv01\installedApps\YourHostNode01Cell\YourApp.ear\YourApp.war\WEB-INF
Check the web_merged.xml for any servlets without a url-pattern mapping. (web_merged.xml has been created by WAS, from the app's web.xml).

In my case, the servlet-name element was missing. This is because I mapped it to a servlet-name which didn't exist.

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)