Can I use EclipseLink (the successor to TopLink) with GlassFish v2?

Yes, this is possible. Here are the steps you need to do:

  • Download the latest EclipseLink release from http://www.eclipse.org/eclipselink/downloads/ (This tutorial is written based on EclipseLink 1.1.1).
  • From the downloaded archive, extract the file eclipselink.jar to the folder <glassfish>/domains/domain1/lib (only for this domain) or <glassfish>/lib (for all domains).
  • Restart GlassFish.
  • Add the following settings to your application's persistence.xml file:
    • <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    • Rename all properties from toplink to eclipselink.
    • If your GlassFish is older than v2.1 (like v2, v2ur1 and v2ur2) then you need to add <property name="eclipselink.target-server" value="SunAS9"/>.
      * If you are using the application client container (ACC) then you must also copy {{eclipselink.jar to your ACC's appclient/lib folder and add the line SET APPCPATH=%AS_INSTALL%\lib\eclipselink.jar to your ACC's appclient/bin/appclient.bat script. A good location is after the line starting with rem Persistence JARs....
  • Redeploy your application.

Note that EclipseLink does not allow zero as a valid primary key value by default. This can lead to the problem that you cannot persist objects with zero as its primary key value in EclipseLink, while it worked well in TopLink. To enable zero as a valid primary key value, you must set the following line in your persistence.xml file and redeploy your application: <property name="eclipselink.allow-zero-id" value="true"/>

Note that EclipseLink's em.find() method now is case sensitive, even if your database is not. This can lead to the problem that em.find() returns no result in EclipseLink while it returned one in TopLink.