Thursday, November 4, 2010

JPA based Enterprise Applications on EE Application Server Containers

20110115: WebLogic Server 10.3.4 has been released with support for JPA 2.0 (JSR-317)

See http://wiki.eclipse.org/EclipseLink/Examples/JPA#Tutorials for more info.

   First things first - configuration....
Administration:
Database:
HSQL 1.8/2.0 (Hypersonic) http://hsqldb.org/
startup script
# java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb
db.url=jdbc:hsqldb:hsql://127.0.0.1/xdb
db.user=sa
db.password=
jdbc.driver.jar=C:/opt/hsqldb_1_8_0_10/lib/hsqldb.jar
db.driver=org.hsqldb.jdbcDriver
db.platform=org.eclipse.persistence.platform.database.HSQLPlatform

Persistence.xml fragment

 
 
 
 
 
 
 

WebLogic Console and JPA Persistence Providers:
    WebLogic ships with support for JPA providers such as EclipseLink and Kodo.  In order to use EclipseLink you will either want to set the <provider> to org.eclipse.persistence.jpa.PersistenceProvider or enable EclipseLink as the default JPA provider for your WebLogic domain.
    Once your EE application is deployed, you may view which persistence units are available either as container managed persistence units via the EJB container or application managed units via the Web container.

 Extended properties such as the container defined JTA data source here can be verified here as well.

GlassFish JPA Deployment:

   Issues:
   EJB module ordering in the application.xml deployment descriptor of your EE EAR is significant in GlassFish - See EclipseLink bug 323148 and comment # 9 of EclipseLink bug 293191. This issue is that weaving/bytecode-instrumentation will not have been run yet on the persistence unit in an EJB module if the WAR module that uses/injects a session bean (itself injected with a persistence context) is processed first.  This EAR module order in the order of use looks to only be an issue with JSF applications. 


Debugging JPA container managed transactional applications in WebLogic Server from Eclipse
If you are regularly debugging client EE or server code running on WebLogic server from an IDE like Eclipse Galileo - you will need to increase the default transaction timeout from 30 seconds to something like 300n seconds.
Otherwise you will see a transaction timout exception like the following - for example during a standard entityManager persist on a stateless session bean that uses a transactional @PersistenceContext injection of the persistence unit.

Stacktrace:
javax.ejb.EJBException: Transaction Rolledback.: weblogic.transaction.internal.TimedOutException: Transaction timed out after 34 seconds
 at weblogic.transaction.internal.ServerTransactionImpl.wakeUp(ServerTransactionImpl.java:1733)
 at weblogic.transaction.internal.ServerTransactionManagerImpl.processTimedOutTransactions(ServerTransactionManagerImpl.java:1578)
 at weblogic.transaction.internal.TransactionManagerImpl.wakeUp(TransactionManagerImpl.java:1900)
 at weblogic.transaction.internal.ServerTransactionManagerImpl.wakeUp(ServerTransactionManagerImpl.java:1488)
 at weblogic.transaction.internal.WLSTimer.timerExpired(WLSTimer.java:35)
 at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273)
 at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
nested exception is: weblogic.transaction.internal.TimedOutException: Transaction timed out after 34 seconds 
 at weblogic.ejb.container.internal.EJBRuntimeUtils.throwEJBException(EJBRuntimeUtils.java:148)
 at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:567)
 at weblogic.ejb.container.internal.BaseLocalObject.__WL_postInvokeTxRetry(BaseLocalObject.java:427)
 at org.eclipse.persistence.example.jpa.server.business.ApplicationService_5ptwty_ApplicationServiceLocalImpl.query(ApplicationService_5ptwty_ApplicationServiceLocalImpl.java:193)
 at org.eclipse.persistence.example.jpa.server.weblogic.enterprise.presentation.FrontController.processGliderCommand(FrontController.java:293)

The following WebLogic console page is used to increase the transaction timeout : Domain|Configuration|JTA


Tomcat Deployment:
Even though Tomcat is only a web container and does not supply a transactional EJB container - we can still deploy JPA applications using application managed sessions.

64 Bit Tomcat: Since tomcat is almost entirely a java application and therefore uses 32/64 bit agnostic bytecode we can run either version on 64 bit operating systems.  The only difference between the 32 and 64 bit versions of tomcat is for the non-java based windows services executable and dll (tcnative-1.dll and tomcat7.exe).  If you run tomcat from the command line then both versions are the same.

Customization:

Referencing Remote Persistence Archives:
Normally the persistence classes (Entities, MappedSuperclasses, Embeddables and Transient classes) are either part of the module containing the persistence.xml descriptor or in a separate jar that is packaged with the application (whether standalone SE or server based EE).

1) Separate Entity jar
For example, in the client SE jar we define persistence.xml in the location /src/META-INF/persistence.xml and reference entities that can be shared between modules.

  
    org.eclipse.persistence.jpa.PersistenceProvider
      org.eclipse.persistence.example.jpa.dataparallel.model.HyperCube
...

No comments:

Total Pageviews

Followers