Thursday May 06, 2010

Updating EclipseLink to a newer version in existing GlassFish V3 installation

GlassFish V3 ships with EclipseLink 2.0 binaries as JPA provider. If you need to update your existing GlassFish installation to a newer version of EclipseLink binaries, you will need to do following

  • Download newer version of EclipseLink binaries from Choose OSGI bundles from the available downloads

  • Replace following files under $GLASSFISH_HOME/glassfish/modules with corresponding jars you downloaded above

    • org.eclipse.persistence.antlr.jar

    • org.eclipse.persistence.jpa.jar

    • org.eclipse.persistence.asm.jar

    • org.eclipse.persistence.jpa.modelgen.jar

    • org.eclipse.persistence.core.jar


    • javax.persistence.jar

  • Restart GlassFish

Monday Mar 02, 2009

Using Hibernate as JPA Provider for GlassFish V3

GlassFish V3 prelude ships with EclipseLink as the default JPA provider. The question that frequently gets asked is: How hard it is to to use Hibernate as the persistence provider with Glassfish V3. The answer is:  Not at all :). It is even simpler to achieve this than it was with V2. Thanks to the wonderful V3 update center it is as easy as 1-2-3. Lets  walk through the steps:

1. Download and install GlassFish V3 prelude with update tool.

2.  Launch the update tool. Hibernate is available under "Available Add-ons" as can be seen below. Check "Hibernate JPA" and click install.

3. GlassFish will be ready to use Hibernate as JPA provider[1]. The file <installdir>/hibernate/overview.txt contains all the information to get you started.

[1] Please note that we had used Derby (also available with the update tool) for testing.

Wednesday May 30, 2007

Using Apache OpenJPA with GlassFish

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:

    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 the provider element to org.apache.openjpa.persistence.PersistenceProviderImpl. Shown below is a sample persistence.xml:

<persistence xmlns="" version="1.0">
<persistence-unit name ="em1">
<!-- Enable SQL Logging for OpenJPA -->
<property name="openjpa.Log" value="DefaultLevel=INFO,SQL=TRACE"/>

Step #5: Build and deploy your app
Now you can build your Java EE application and deploy it to GlassFish.

Monday Apr 03, 2006

Use Hibernate as a persistence provider with Glassfish

As you must be aware, Glassfish currently has Toplink Essentials as the default persistence provider. The question that frequently gets asked is: How hard it is to to use hibernate as the persistence provider with Glassfish?
The answer is:  Not at all :). Just drop couple of jars reqired by hibernate in the lib directory of Glassfish and modify your persistence.xml to use hibernate as the provider and you are ready to go. Lets walk through the steps:

1. Download and install glassfish milestone 6 build or later.
2. Download and install Hibernate3 3.2cr1 or later.
3. Download and install Hibernate EntityManager 3.1 beta7 or later.
4. Copy the required hibernate jars into Glassfish lib dir. The script here contains the list of jars.
5. Update your persistence.xml to use hibernate as the persistence provider. Here is a sample persistence.xml
6. Deploy and run your application.


Thursday Jan 19, 2006

DataBase Platform AutoDetection

Platform Auto Detection In Glassfish Any persistence provider communicating with relational database needs to generate SQL. Unfortunately, the SQL dialect to use varies slightly from one database vendor to another. Typically the user would need to provide a hint  about the database vendor  whose SQL dialect is to be used. For example, Glassfish needs the property “” to point to the class name that corresponds to the database vendor being used.

If you look at a typical persistence.xml, you will notice that the information about database vendor is specified twice:
  • Connection properties either as data source or as jdbc properties
  • Property "" to specify the SQL dialect.

Here is an example of a persistence.xml connecting to a Derby database:
<persistence .....   >
    <persistence-unit .... >
            <!-- JDBC connection properties -->
            <property name="jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
            <property name="jdbc.connection.string" value="jdbc:derby://localhost:1527/testdb;retrieveMessagesFromServerOnGetMessage=true;create=true;"/>
            <property name="jdbc.user" value="yourusername"/>
            <property name="jdbc.password" value="yourpassword"/>

        <!-- SQL dialect to use -->
        <property name ="" value =  "oracle.toplink.essentials.platform.database.DerbyPlatform"/>

We have implemented a feature in Glassfish to automatically detect the database vendor based on the connection properties (datasource or jdbc). Internally this feature is called "Platform Auto Detection". By introducing this feature, we have removed the above mentioned duplication and consequently improved the end user experience. Below is a FAQ on this feature.

How does one enable "Platform Auto Detection" ?
Omit the property "" from your persistence.xml. If this property is not provided, it is a hint to Glassfish to automagically detect the database vendor.

How do I know the platform that was automatically detected by Glassfish Persistence runtime?
This can be achieved by enabling the logging level for Glassfish Persistence runtime. When this logging level is set to "FINE" check the log messages for a string that reads "Detected Vendor platform: <the detected platform>".

How does one enable the log level for Glassfish Persistence runtime?
Define a property "toplink.logging.level" in your persistence.xml with the desired log level ("INFO/FINE/FINEST").
<property name="toplink.logging.level" value="FINE"/>

Where can I find more information on how this is implemented in Glassfish ?
Glassfish adopts a 2 step approach to achieve this :
  1.  java.sql.DatabaseMetaData#getDatabaseProductName() is called on the connection to get the database product name
  2. The product name is then matched against a set of regular expressions to compensate for variations in the product name that are returned by different jdbc drivers. This matched regular expression maps to the appropriate database platform class name,
Further information can be be found in


Mitesh Meswani


« July 2016