Last year Sahoo blogged about using OpenJPA with GlassFish. OpenJPA has evolved a lot since then. It has graduated from incubator to a top level project at Apche. It is also passing JPA TCK. I tried to use OpenJPA with Glassfish V2 . It was very easy to do so. Here are the steps I followed
Step 1: Downnload and install GlassFish
Download any of the latest builds of GlassFish v2 or v1_ur1 from here. Install it in any directory of your choice. I refer to that as GLASSFISH_HOME
Step #2: Install OpenJPA
Download a nightly snapshot of OpenJPA 1.0.0 from here. Unzip this to any location. In this blog, I refer to that location as OPENJPA_HOME.
Step #3: Install OpenJPA in GlassFish
All you need to do is to make OpenJPA implementation jar files and its runtime dependency files available to GlassFish runtime. This can be achieved as follows:
cd $OPENJPA_HOME
cp openjpa-1.0.0-SNAPSHOT.jar lib/commons-*.jar lib/serp-1.11.0.jar $GLASSFISH_HOME/domains/domain1/lib
GlassFish will automatically make this jar part of its classpath next time when you restart the server. Please note that $OPENJPA_HOME/lib/geronimo*.jar are not required to be copied as GlassFish already contains equivalent jars. Same is true for $OPENJPA_HOME/lib/derby*.jar
Step #4: Edit persistence.xml
Make a one line change to your persistence.xml to instruct GlassFish
that we want to use OpenJPA as the persistence provider for this
application. This is achieved by setting
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name ="em1">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<!-- Enable SQL Logging for OpenJPA -->
<property name="openjpa.Log" value="DefaultLevel=INFO,SQL=TRACE"/>
</properties>
</persistence-unit>
</persistence>
Step #5: Build and deploy your app
Now you can build your Java EE application and deploy it to GlassFish.
Posted by Mayank Mishra on May 30, 2007 at 11:06 PM PDT #
Posted by 196.12.47.8 on May 31, 2007 at 09:42 PM PDT #
Posted by Sherry Shen on June 05, 2007 at 04:47 PM PDT #
java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider
Consequently, my application will not load.Posted by Ulrich Mayring on June 14, 2007 at 01:33 AM PDT #
Posted by Mitesh on June 14, 2007 at 01:12 PM PDT #
Getting exception NoClassDefFoundError: oracle/dms/instrument/ExecutionContextForJDBC
Using OpenJPA 1.0.2, Sun Java System Application Server 9.1_01 (build b09d-fcs)
Posted by Johan Wester on May 30, 2008 at 04:56 AM PDT #
Solved problem - seems you need dms.jar (was not mentioned above).
Also, putting dms.jar in the $GLASSFISH_HOME/domains/domain1/lib does not work
I had to put it in $GLASSFISH_HOME/domains/domain1/lib/ext
Posted by Johan Wester on May 30, 2008 at 05:16 AM PDT #
Glassfish v.2.1, OpenJPA 1.2.1(1.3) not properly working with remote client. On remote side i create Entity with not null fields and try persist this entity by invoking remote ejb method. On server side appear entity with null fields and persist() throw javax.transaction.RollbackException. With Toplink all work.
Posted by Jeank on August 04, 2009 at 05:27 AM PDT #
I assume you are passing the entity to a remote EJB method that invokes em.persist. Are you receiving the entity correctly on the remote side? What kind of remote client are you using?
Posted by Mitesh Meswani on August 04, 2009 at 12:17 PM PDT #
On remote side all correct - before invocation remote EJB method i cheked all fields of entity. Remote client - java Swing client
Posted by Jeank on August 06, 2009 at 07:18 AM PDT #
You have checked entity on swing client side. Did you check on EJB side whether the entity made through without any issues?
Posted by Mitesh Meswani on August 06, 2009 at 02:54 PM PDT #
On EJB side i have entity with nulls fields (wrote in first post), i.e. absolutely new entity with not setting fields. But if i use method which get entity using id (Long type) - it works. I checked this ejb on OpenEJB standalone server and on Glassfish with Toplink and Hibernate - all works.
Posted by Jeank on August 06, 2009 at 11:00 PM PDT #