Configuring WebLogic 8.1 and Hibernate 3.0 - Part II
Prakash Malani's Blog | July 29, 2005 03:02 PM | Comments (5)
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 09: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 05: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 05: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