Wednesday, March 26, 2008

Using TopLink Essentials as the JPA Provider for WebLogic 10

A couple of weeks ago, one customer asked me for instructions for using TopLink Essentials as the JPA provider with WebLogic 10. I thought I would give it a try as I’m working on migrating my book examples to WebLogic 10.

First, you have to download TopLink Essentials either from OTN or Glassfish web site.
I packaged the toplink-essentals.jar, toplink-essentials-agent.jar in the lib directory for the EAR so the structure of EAR looked like as follows:

chapter2-ejb.jar
lib/toplink-essentials.jar
lib/toplink-essentials-agent.jar

I specified provider class oracle.toplink.essentials.PersistenceProvider
in my persistence.xml packaged in my EJB module as follows:

<persistence-unit name="actionBazaar">
<provider>
class oracle.toplink.essentials.PersistenceProvider
</provider>
<properties>
<property name="toplink.ddl-generation" value="create-tables"> <property name="toplink.ddl-generation.output-mode" value="database">

If you want to use container managed entity manager with WebLogic’s JTA transaction manager you have to create your server platform class by extending oracle.toplink.essentials.transaction.JTATransactionController as follows:

package debu.weblogic;
import javax.transaction.TransactionManager;
import oracle.toplink.essentials.transaction.JTATransactionController;

public class WebLogicTransactionController extends JTATransactionController
{

private static final String WLS_TRANSACTION_MANAGER_NAME = "javax.transaction.TransactionManager";
public WebLogicTransactionController(){

}

protected TransactionManager acquireTransactionManager() throws Exception {
TransactionManager tm = (TransactionManager)jndiLookup(WLS_TRANSACTION_MANAGER_NAME);
return tm;
}
}

As you might have seen already that I’ve specified this class as the target-server property in persistence class.

You can package this class as a part of your application in the same EAR file where you packaged the TopLink Essentials jar files and the entity classes.

Using TopLink 11 with WebLogic 10

If you are using TopLink 11 preview (or EclipseLink) you do not have to create your own server platform class but you can use the server platform shipped in toplink.jar for WebLogic 10.

Here is how your persistence.xml look like when you use TopLink 11.

<persistence-unit name="actionBazaar">
<provider>
oracle.toplink.PersistenceProvider
</provider>
<jta-data-source>
jdbc/ActionBazaarDS</jta-data-source>

<properties>
<property name="toplink.ddl-generation" value="create-tables">
<property name="toplink.ddl-generation.output-mode" value="database">

<property name="toplink.target-server" value="WebLogic_10">

</property>


Note that you have to package toplink-ojdbc.jar in addition to toplink.jar and antlr.jar if you are using Oracle DB as the underlying database.

Hope this helps.
Need to go to bed, feeling sleepy now!

1 comment:

Vijendra said...

I am trying to use Toplink on weblogic10.3 I get exception as "javax.ejb.EJBException: EJB Exception: : javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro" Can someone please help me resolve this ?
Here's complete stack trace
WARNING: Found unrecognized persistence provider "oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider" in place of OpenJPA provider. This provider's properties will not be used.
WARNING: Found unrecognized persistence provider "oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider" in place of OpenJPA provider. This provider's properties will not be used.
Dec 3, 2008 11:23:43 AM PST Error ServletContext-/hcp BEA-000000 Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.medtronic.diabetes.ipro.webapp.client.FilterTableService.getPatientList()' threw an unexpected exception: javax.ejb.EJBException: EJB Exception: : javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getEMF(DAOServiceBean.java:23)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getDAO(DAOServiceBean.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:15)
at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:30)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
at $Proxy105.getDAO(Unknown Source)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean_hdxjoa_DAOServiceImpl.getDAO(DAOServiceBean_hdxjoa_DAOServiceImpl.java:60)
at com.medtronic.diabetes.ipro.webapp.hcp.servlets.FilterTableServiceImpl.getPatientList(FilterTableServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
; nested exception is: javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:360)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:546)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Truncated. see log file for complete stacktrace
javax.ejb.EJBException: EJB Exception: : javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getEMF(DAOServiceBean.java:23)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getDAO(DAOServiceBean.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:15)
at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:30)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
at $Proxy105.getDAO(Unknown Source)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean_hdxjoa_DAOServiceImpl.getDAO(DAOServiceBean_hdxjoa_DAOServiceImpl.java:60)
at com.medtronic.diabetes.ipro.webapp.hcp.servlets.FilterTableServiceImpl.getPatientList(FilterTableServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
; nested exception is: javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro
at weblogic.ejb.container.internal.EJBRuntimeUtils.throwEJBException(EJBRuntimeUtils.java:151)
at weblogic.ejb.container.internal.BaseLocalObject.handleSystemException(BaseLocalObject.java:850)
at weblogic.ejb.container.internal.BaseLocalObject.handleSystemException(BaseLocalObject.java:791)
at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:486)
at weblogic.ejb.container.internal.BaseLocalObject.postInvokeTxRetry(BaseLocalObject.java:424)
Truncated. see log file for complete stacktrace
javax.persistence.PersistenceException: No Persistence provider for EntityManager named ipro
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getEMF(DAOServiceBean.java:23)
at com.medtronic.diabetes.ipro.ejb.dataaccess.DAOServiceBean.getDAO(DAOServiceBean.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Truncated. see log file for complete stacktrace

I have common module which is used for data access and this module is not part of my application. persistence.xml is under common\src\META-INF. I have made a jar of the common module and included as a library in my application.

I have common module which is used for data access and this module is not part of my application. persistence.xml is under common\src\META-INF. I have made a jar of the common module and included as a library in my application.
(persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0")
(persistence-unit name="ipro")
(!-- Provider class name is required in Java SE --)
(provider)oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider(/provider)
(!-- All persistence classes must be listed --)
(class)com.ipro.persistence.IProEntity(/class)
(class)com.ipro.persistence.Account(/class)
(class)com.ipro.persistence.Csr(/class)
(class)com.ipro.persistence.Device(/class)
(class)com.ipro.persistence.Report(/class)
(class)com.ipro.persistence.ReportPreferences(/class)
(class)com.ipro.persistence.Clinic(/class)
(class)com.ipro.persistence.Patient(/class)
(class)com.ipro.persistence.Study(/class)
(class)com.ipro.persistence.ClinicWorker(/class)
(class)com.ipro.persistence.DeviceSnapshot(/class)
(class)com.ipro.persistence.AuditEvent(/class)
(properties)
(!-- Provider-specific connection properties --)
(property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/)
(property name="toplink.jdbc.url" value="jdbc:oracle:thin:@oradev04.ols.minimed.com:1521:IPR"/)
(property name="toplink.jdbc.user" value="user"/)
(property name="toplink.jdbc.password" value="pswd"/)
(!-- Provider-specific settings --)
(property name="toplink.logging.level" value="FINE"/)
(/properties)
(/persistence-unit)
(/persistence)