{"id":99,"date":"2011-02-15T20:31:35","date_gmt":"2011-02-16T03:31:35","guid":{"rendered":"http:\/\/sloanseaman.com\/wordpress\/?p=99"},"modified":"2011-07-17T10:01:06","modified_gmt":"2011-07-17T17:01:06","slug":"websphere-hibernate-jpa-with-a-twish-of-classpath-hell","status":"publish","type":"post","link":"http:\/\/sloanseaman.com\/wordpress\/2011\/02\/15\/websphere-hibernate-jpa-with-a-twish-of-classpath-hell\/","title":{"rendered":"Websphere, Hibernate, JPA, with a twist of Classpath hell"},"content":{"rendered":"<h3>Problem<\/h3>\n<p>Recently I had to take a .war project that utilized Hibernate 3.5 and JPA 2.0 and deploy it in WebSphere 7.0.  It has been quite a long time since I worked with WebSphere and was very happy to find that it was very easy to setup and deploy my existing war.<\/p>\n<p>What I didn&#8217;t expect was the Classpath mess that was to ensue and the 7 hours of research to find a solution to what appears to be a fairly common problem (but no real solution defined)<\/p>\n<p>You see, WebSphere ships with a copy of OpenJPA.  OpenJPA is a JPA implementation that WebSphere provides for use by developers.  It just so happens though that the OpenJPA that WebSphere ships with is a JPA 1.0 implementation.  <\/p>\n<p>Hibernate 3.5 or > requires a JPA 2.0 implementation. Houston, we have a problem.<\/p>\n<p>No problem you think.  I&#8217;ve got the JPA 2.0 implementation (hibernate-jpa-2.0-api01.0.0.Final.jar) in my .war&#8217;s classpath, so I&#8217;m fine. Right?<\/p>\n<p>Wrong.  WebSphere puts OpenJPA on the Classpath first, no matter what.  You can change the configurations (Parent first\/Parent last) and it will still have OpenJPA on the Classpath before the .war file.  You&#8217;ll start seeing a lot of weird errors like:<br \/>\n<code>java.lang.NoSuchMethodError: javax\/persistence\/spi\/PersistenceUnitInfo.xxxx<\/code><\/p>\n<p>If you see the above you have a JPA 1.0\/JPA 2.0 issue because of OpenJPA.  <\/p>\n<h3>Solution<\/h3>\n<p>IBM has a Feature Pack (think library upgrade package) for WebSphere to get it to run OSGi and JPA 2.0.  Once you install this everything should work fine.<\/p>\n<p>Steps:<\/p>\n<ol>\n<li>Shutdown WebSphere<\/li>\n<li>Download the IBM Install Manager at <a href=\"http:\/\/www-01.ibm.com\/support\/docview.wss?uid=swg24027833\">http:\/\/www-01.ibm.com\/support\/docview.wss?uid=swg24027833<\/a> if you don&#8217;t already have it.<\/li>\n<li>Start the IBM Installation Manager\n<ol>\n<li>Make the Install Manager aware of your WebSphere installation if it isn&#8217;t already\n<ol>\n<li>Select IMPORT from the main page<\/li>\n<li>Select the installation directory of your copy of WebSphere<\/li>\n<li>Select next for the rest of the steps until finished<\/li>\n<\/ol>\n<\/li>\n<li>Back at the main IBM Installation Manager screen select INSTALL\n<ol>\n<li>Select the Feature Pack for OSGi Applications and JPA 2.0<\/li>\n<li>Install the Feature Pack<\/li>\n<\/ol>\n<\/li>\n<li>Once done, exit the IBM Installation Manager<\/li>\n<\/ol>\n<\/li>\n<li>Start the IBM Profile Manager\n<ol>\n<li>In the Profile Manager, Select the Server then click AUGMENT<\/li>\n<li>Select the JPA 2.0 and click NEXT then click INSTALL<\/li>\n<li>Exit the IBM Profile Manager<\/li>\n<\/ol>\n<\/li>\n<li>Start up WebSphere\n<ol>\n<li>To Verify that the install took:\n<ol>\n<li>Go to the web interface for the WebSphere server<\/li>\n<li>Select SERVERS -&gt; SERVER TYPE -&gt; WEBSPHERE APPLICATION SERVERS -&gt; SERVER1 -&gt; RUNTIME -&gt; PRODUCT INFORMATION<\/li>\n<li>You should see &#8216;Feature Pack for OSGi Applications and Java Persistence API 2.0&#8217;<\/li>\n<\/ol>\n<\/li>\n<li>Uninstall your .war, .ear, .etc and reinstall it<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>The errors should disappear and everything should start working!<\/p>\n<h3>Things to note<\/h3>\n<ul>\n<li>You need to be running WebSphere 7.0.0.9 or greater.  If you aren&#8217;t, you can&#8217;t use the Feature Pack<\/li>\n<li>You may need to define the persistence provider in your <i>persistence.xml<\/i> file.  I didn&#8217;t have to but I found many sites suggesting that it was the solution (it wasn&#8217;t, but it couldn&#8217;t hurt). If you want to try it:\n<ul>\n<li>Add <code>&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;\/provide&gt;<\/code> between your <code>&lt;persistence-unit&gt;<\/code> tags<\/li>\n<li>You will notice Hibernate starts up as soon as your app starts in WebSphere.  If you haven&#8217;t fixed the above error (<code>java.lang.NoSuchMethodError<\/code>) you will just see it sooner and your app won&#8217;t start<\/li>\n<\/ul>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Problem Recently I had to take a .war project that utilized Hibernate 3.5 and JPA 2.0 and deploy it in WebSphere 7.0. It has been quite a long time since I worked with WebSphere and was very happy to find &hellip; <a href=\"http:\/\/sloanseaman.com\/wordpress\/2011\/02\/15\/websphere-hibernate-jpa-with-a-twish-of-classpath-hell\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,10],"tags":[],"_links":{"self":[{"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":15,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":167,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/posts\/99\/revisions\/167"}],"wp:attachment":[{"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sloanseaman.com\/wordpress\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}