Configuring WebLogic 8.1 and Hibernate 3.0 - Part II
Prakash Malani's Blog |
July 29, 2005 3:02 PM
|
Comments (8)
My previous blog entry described step-by-step instructions on configuring WebLogic 8.1 with Hibernate 3.0. The response and interest in the entry has been tremendous! In this blog entry, I evaluate advanced configuration where Hibernate leverages WebLogic's implementation of Java Naming and Directory Interface (JNDI), Java Transaction API (JTA), Java Connector Architecture (JCA), and Java Management eXtensions (JMX).
Let me start with JNDI. Just by naming the SessionFactory in the hibernate.cfg.xml file, Hibernate makes the SessionFactory available in the JNDI. Alas! This does not work for WebLogic. As described here WebLogic JNDI and Hibernate do not play well together. There are multiple workarounds. The workarounds manually bind the SessionFactory with in the JNDI either via a WebLogic startup class or a start-up servlet. However, I was not able to get the SessionFactory instance reliably back from the JNDI. Therefore, a reasonable compromise is to add an accessor for the SessionFactory to the HibernateUtil utility class.
In order to configure Hibernate to use JTA, I configured transaction.factory_class in the hibernate.cfg.xml file. There are two possible options: org.hibernate.transaction.JTATransactionFactory and org.hibernate.transaction.CMTTransactionFactory. The documentation recommends using the JTATransactionFactory for a bean with Bean Managed Transaction Demarcation (BMTD) and CMTTransactionFactory for a bean with Container Managed Transaction Demarcation (CMTD). The JTATransactionFactory seems more generic of the two transaction factories. It seems to support beans with BMTD as well as CMTD. Therefore, I configured JTATransactionFactory. Additionally, to lookup a transaction in a container-specific way, I configured transaction.manager_lookup_class in the hibernate.cfg.xml file. With this configuration, I do not need to use the Hibernate Transaction API at all as illustrated in the DomainManagerBean.updateWorkPhone() method.
JCA support for Hibernate is experimental and currently not fully baked for WebLogic. In the future, I can imagine that Hibernate is packaged as Resource ARchive (RAR) file. The Hibernate RAR file is deployed as a resource adapter. The adapter makes the Session available in the JNDI. All the configuration elements are done with the resource adapter (xml file) instead of the hibernate.cfg.xml file or by some other means. Why configure Hibernate using JCA into WebLogic? JCA is designed to encapsulate legacy system's connections, transactions, etc. and make them available in the J2EE world. However, Hibernate is designed from group up to play well in the J2EE world. Therefore, the traditional resource adapter benefits are not fully realized. Once Hibernate is configured as a resource adapter, the coupling of specific applications to Hibernate is weakened a little. Multiple different applications can leverage the same Hibernate resource adapter. The benefits of this configuration will be even more pronounced with the standardization of persistence APIs of Enterprise JavaBeans (EJBs), Hibernate, and Java Data Objects (JDO) with current ongoing EJB 3.0 effort. Theoretically, hot (re)deploying the adapter and changing the persistence implementation is possible.
Hibernate ships with JMX Management Bean (MBean) implementation. I did not see a way to deploy Hibernate into WebLogic using JMX. What are the benefits of leveraging JMX with Hibernate and WebLogic? I see at least two benefits. One is deployment as well as re-deployment. But, more importantly is being able to monitor Hibernate and obtain statistics. Runtime monitoring from a JMX console is essential for health and caring of a deployed application.
Please try out these new additional configurations. I have updated the sample application, and it is available here. (Note: Free membership to bartsandbox is required.) I look forward to hearing your experiences on leveraging WebLogic's implementation of JNDI, JTA, JCA, and JMX with Hibernate. Comments, feedback, and questions are most welcome.
In the future blog, entries I will discuss Spring integration with WebLogic 8.1 as well as Hibernate 3.0. So please stay tuned...
Best regards,
+prakash
-----
My blog (http://dev2dev.bea.com/blog/pmalani/)
Answers to J2EE, Java, UML, Process, and Patterns! (http://www.bartssandbox.com/)
Los Angeles BEA Users Group (http://groups.yahoo.com/group/LABEAUG/)
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
I appologize if this question has already been answered. I don't want to use WLW but I do want to use weblogic 8.1sp4.
Could you explain how to get Hibernate 3.0 running with WL 8.1sp4 from the linux console, talking to a mysql db. I've got the JDBC pool running, JNDI setup but not tested, Hibernate 3.0 running with ~70% of its JUnit test being successful.
If there are specific reasons why you are ".. not comfortable with the dependencies from Java or EJB projects (modules into a Web project (module)." could you please explain them?
Cheers,
Seth
Posted by: sethatklipmart on August 17, 2005 at 9:06 AM
-
nevermind. We are going with Spring.
Posted by: sethatklipmart on August 17, 2005 at 12:08 PM
-
Has anybody been able to deploy hibernate 3.0 to WebLogic 9.0 using the same theory above? Im really interested in finding a way to use the JMX API's to do both deploy's and remote mgmt. Thanks in advance!!
Posted by: robert.heise on October 13, 2005 at 5:55 PM
-
I am trying to bind the Hibernate 3.0.5 SessionFactory to the Weblogic 8.1 JNDI on the cluster. For this I did the following.
1. Wrote a startup class to instantiate a SessionFactory like this.
SessionFactory sessionFactory = new Configuration().configure(cfgFile)
.buildSessionFactory();
where cfgfile is a user passed parameter to the startup class and is by default hibernate.cfg.xml.
2. My hibernate.cf.xml looks like this.
t3://localhost:7001
weblogic.jndi.WLInitialContextFactory
jdbc/myDataSource
true
org.hibernate.dialect.PointbaseDialect
org.hibernate.transaction.CMTTransactionFactory
org.hibernate.transaction.WeblogicTransactionManagerLookup
3. I configured the startup class in the Deployment section of Admin Console.
Results
1. If this startup class is targeted to one server like the admin server, it binds the SessionFactory to the JNDI tree in the admin server.
2. If this startup class is targeted to the cluster then the startup code runs fine without any fatal exception on all the managed servers but does not bind the SessionFactory to the JNDI name specified in the hibernate.cfg.xml file on either of the managed servers. The only difference I see between the execution of this startup code on a single server as opposed to on a cluster is that I see the following warning message logged by one of the Hibernate classes.
"WARN SessionFactoryObjectFactory:101 -InitialContext did not implement EventContext"
Has anyone faced a simple problem while starting to bind the SessionFactory to the Weblogic Cluster?
Posted by: rn056569 on November 16, 2005 at 5:24 PM
-
I am using Weblogic 9.0 and Hibernate 3.0.
I have developed a session bean which invokes hibernate object.
EJB had been deployed successfully. When the EJB tries to get hold of Hibernate session factory , nothing happens.
Also I have defined a datasource in weblogic server by giving JNDI name
Could u pl tell me what I have to do to make this work
Regards
seshadri
Posted by: SESHADRI on November 18, 2005 at 12:19 AM
-
Hi,
I have an issue in my project (Scratch one).
I have an web application. In that I use the startup servlet to bind the Hibernate SessionFactory object in init() method.
Then I deployed it in the Weblogic server. After deployed, the object is bounded. I can see the object in Weblogic JNDI tree.
Startup Servlet:
In the init() method:
try {
factory = new Configuration().configure().buildSessionFactory(); //here it bind the Sessionfactory object in weblogic server
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
Hibernate.cfg.xml:
SessionFactory
weblogic.jndi.WLInitialContextFactory
t3://localhost:7001
jdbc/DSJNDI
org.hibernate.transaction.WeblogicTransactionManagerLookup
org.hibernate.transaction.JTATransactionFactory
thread
org.hibernate.dialect.MySQL5Dialect
Then I wrote another web application. In the servlet I'm lookup the same bounded object. But it's return null.
Client Servlet:
In doGet() method:
String URL = "t3://localhost:7001";
String INITIAL_CONTEXT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
environment.put(Context.PROVIDER_URL, URL);
Context context = new InitialContext(environment);
objref = context.lookup("SessionFactory"); // JNDI Name
System.out.println("Object is ************: "+objref); //here itself throwing null
SessionFactory sessionFactory = (SessionFactory) PortableRemoteObject.narrow(objref, SessionFactory.class);
Stacktrace:
java.lang.NullPointerException: narrowFrom'null' narrowTo:'interface org.hibernate.SessionFactory'It is invalid to call narrow with null parameters
at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:94)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at com.rci.client.RCIClient.testSessionFactory(RCIClient.java:60)
at com.rci.client.RCIClient.doGet(RCIClient.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
Posted by: prakash.rajo on October 12, 2007 at 4:26 AM
-
Hi,
I'm facing a problem deploying application in Weblogic 8.1. I use Spring framework and hibernate 3 in the project and it works fine in Tomcat 5. While I deployed the application in Weblogic I get the following error:
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x80C14B4
Function=JVM_RegisterPerfMethods+0x1297D
Library=D:\bea\JDK142~1\jre\bin\client\jvm.dll
Current Java thread:
at java.lang.Class.getName(Native Method)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.springframework.aop.aspectj.annotation.BeanFactoryAspectJAdvisorsBuilder.(BeanFactoryAspectJAdvisorsBuilder.java:42)
at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.initBeanFactory(AnnotationAwareAspectJAutoProxyCreator.java:76)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.setBeanFactory(AbstractAdvisorAutoProxyCreator.java:60)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1101)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
- locked (a java.util.LinkedHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:683)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:451)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:337)
- locked (a java.lang.Object)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:311)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:258)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:229)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:115)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:1018)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:894)
- locked (a weblogic.servlet.internal.ServletStubImpl)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:873)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:812)
- locked (a weblogic.servlet.internal.ServletStubImpl)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:3281)
at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:3226)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3207)
- locked (a weblogic.servlet.internal.WebAppServletContext)
at weblogic.servlet.internal.HttpServer.preloadResources(HttpServer.java:694)
at weblogic.servlet.internal.WebService.preloadResources(WebService.java:483)
at weblogic.servlet.internal.ServletInitService.resume(ServletInitService.java:30)
at weblogic.t3.srvr.SubsystemManager.resume(SubsystemManager.java:131)
at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:966)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:361)
at weblogic.Server.main(Server.java:32)
Dynamic libraries:
0x00400000 - 0x00406000 D:\bea\JDK142~1\bin\java.exe
0x7C900000 - 0x7C9B0000 C:\WINDOWS\system32\ntdll.dll
0x7C800000 - 0x7C8F5000 C:\WINDOWS\system32\kernel32.dll
0x77DD0000 - 0x77E6B000 C:\WINDOWS\system32\ADVAPI32.dll
0x77E70000 - 0x77F02000 C:\WINDOWS\system32\RPCRT4.dll
0x77FE0000 - 0x77FF1000 C:\WINDOWS\system32\Secur32.dll
0x77C10000 - 0x77C68000 C:\WINDOWS\system32\MSVCRT.dll
0x08000000 - 0x08138000 D:\bea\JDK142~1\jre\bin\client\jvm.dll
0x7E410000 - 0x7E4A0000 C:\WINDOWS\system32\USER32.dll
0x77F10000 - 0x77F57000 C:\WINDOWS\system32\GDI32.dll
0x76B40000 - 0x76B6D000 C:\WINDOWS\system32\WINMM.dll
0x10000000 - 0x10007000 D:\bea\JDK142~1\jre\bin\hpi.dll
0x003A0000 - 0x003AE000 D:\bea\JDK142~1\jre\bin\verify.dll
0x003C0000 - 0x003D9000 D:\bea\JDK142~1\jre\bin\java.dll
0x003E0000 - 0x003ED000 D:\bea\JDK142~1\jre\bin\zip.dll
0x02D80000 - 0x02D8F000 D:\bea\jdk142_04\jre\bin\net.dll
0x71AB0000 - 0x71AC7000 C:\WINDOWS\system32\WS2_32.dll
0x71AA0000 - 0x71AA8000 C:\WINDOWS\system32\WS2HELP.dll
0x71A50000 - 0x71A8F000 C:\WINDOWS\System32\mswsock.dll
0x76F20000 - 0x76F47000 C:\WINDOWS\system32\DNSAPI.dll
0x76FB0000 - 0x76FB8000 C:\WINDOWS\System32\winrnr.dll
0x76F60000 - 0x76F8C000 C:\WINDOWS\system32\WLDAP32.dll
0x751D0000 - 0x751EE000 C:\WINDOWS\system32\wshbth.dll
0x77920000 - 0x77A13000 C:\WINDOWS\system32\SETUPAPI.dll
0x76FC0000 - 0x76FC6000 C:\WINDOWS\system32\rasadhlp.dll
0x02EA0000 - 0x02EA8000 D:\bea\jdk142_04\jre\bin\nio.dll
0x02EB0000 - 0x02EB6000 D:\bea\jdk142_04\jre\bin\ioser12.dll
0x662B0000 - 0x66308000 C:\WINDOWS\system32\hnetcfg.dll
0x71A90000 - 0x71A98000 C:\WINDOWS\System32\wshtcpip.dll
0x76C90000 - 0x76CB8000 C:\WINDOWS\system32\imagehlp.dll
0x59A60000 - 0x59B01000 C:\WINDOWS\system32\DBGHELP.dll
0x77C00000 - 0x77C08000 C:\WINDOWS\system32\VERSION.dll
0x76BF0000 - 0x76BFB000 C:\WINDOWS\system32\PSAPI.DLL
Heap at VM Abort:
Heap
def new generation total 2304K, used 280K [0x10010000, 0x10290000, 0x10f70000)
eden space 2048K, 8% used [0x10010000, 0x1003d6a0, 0x10210000)
from space 256K, 38% used [0x10250000, 0x10268c80, 0x10290000)
to space 256K, 0% used [0x10210000, 0x10210000, 0x10250000)
tenured generation total 30272K, used 12556K [0x10f70000, 0x12d00000, 0x1c810000)
the space 30272K, 41% used [0x10f70000, 0x11bb31c0, 0x11bb3200, 0x12d00000)
compacting perm gen total 20480K, used 20248K [0x1c810000, 0x1dc10000, 0x24810000)
the space 20480K, 98% used [0x1c810000, 0x1dbd6188, 0x1dbd6200, 0x1dc10000)
Local Time = Fri Feb 01 15:12:33 2008
Elapsed Time = 6
#
# HotSpot Virtual Machine Error : EXCEPTION_ACCESS_VIOLATION
# Error ID : 4F530E43505002EF
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_04-b05 mixed mode)
#
Thanks,
Ibopishak
Posted by: ibopishak on February 1, 2008 at 1:43 AM
-
This looks like a JVM crash. Is this consistent? If it is... I would try a later version of 1.4.2 jdk.
Best regards,
+prakash
Posted by: pmalani on February 1, 2008 at 5:03 PM
|