users@glassfish.java.net

Re: how to replace TopLink Essentials with EclipseLink in GFv2ur2

From: <glassfish_at_javadesktop.org>
Date: Fri, 16 Jan 2009 06:51:51 PST

Smart choice.... I just recently had to do this.... and this is what I did.

Goto
http://www.eclipse.org/eclipselink/downloads/
Download the files.....
Get the eclipselink.jar and the javax.persistence_1.0.0.jar file and put them in your ear file. (In eclipse I put them under the EarContent directory so that the entire ear project had access to them)

Then goto your EJB project that is associated under that EAR project and make sure to add them to the EJB project (under eclipse its under Right Click -> Properties -> J2EE Module Dependencies -> click on eclipselink.jar and javax.persistence_1.0.0.jar)

Then in your persistence.xml file add the following...
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>


Example:

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="common" transaction-type="RESOURCE_LOCAL">
       <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
       <jta-data-source>jdbc/testdb</jta-data-source>
    </persistence-unit>
</persistence>

And that should do it. Your EJB should now be using EclipseLink rather than TopLink.
Note you will now be able to login with credentials when creating the EntityManager.... as well as have scrollable cursors...

Example:

java.util.Properties map = new java.util.Properties();
                        map.put("eclipselink.jdbc.user", "test");
                        map.put("eclipselink.jdbc.password", "testpassword");
                        em= emf.createEntityManager(map);
                        
org.eclipse.persistence.queries.ReadAllQuery query = new org.eclipse.persistence.queries.ReadAllQuery(SomeClass.class);
                        query.doNotCacheQueryResults();
                        query.setIsReadOnly(true);
                        query.dontMaintainCache();
                        query.setSQLString("SELECT * FROM TESTTABLE");
                        query.setFetchSize(10000);
                        query.useScrollableCursor(10000);
                        
                        // Required for Postgres Cursors
                        ScrollableCursorPolicy policy = new ScrollableCursorPolicy();
                        policy.setResultSetType(ScrollableCursorPolicy.TYPE_FORWARD_ONLY);
                        policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY);
                        query.useScrollableCursor(policy);
                        
                        org.eclipse.persistence.jpa.JpaEntityManager emJPA = org.eclipse.persistence.jpa.JpaHelper.getEntityManager(em);
                        emJPA.getUnitOfWork().beginEarlyTransaction();
                        
                        cursor=(ScrollableCursor) emJPA.getActiveSession().executeQuery(query);
while (!cursor.isLast())
{
  SomeClass class = cursor.next();
}
emJPA.getUnitOfWork().commit();
emJPA.close();


Hope this helps....
[Message sent by forum member 'enderfake' (enderfake)]

http://forums.java.net/jive/thread.jspa?messageID=326480