Prakash Malani's Blog | July 21, 2005聽聽04:00 PM | Comments (25)
Recently, I was asked for step-by-step instructions for configuring Hibernate with WebLogic on bartsandbox. As you may already know, Hibernate is a very popular open source Object Relational Mapping (ORM) tool. Follow these steps to configure Hibernate with WebLogic 8.1.
The complete, working, and self-contained sample application is available here. This includes the schema and all the Hibernate configuration files. (Note: Free membership to bartsandbox is required.)
In the next few blog entries, I will enhance this basic configuration. In meantime, try out the above steps. Comments, questions, and feedback are most welcome.
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/)
managed to run the sample application without much problem. It's very useful to have a sample that I can dissect around instead of the usual html article. Thanks!
There's something that puzzling here. I refer you to Weblogic+Hibernate problem. Though I removed the ant-antlr-1.6.3.jar from APP-INF and re-built the application, I could not reproduce the problem.
So it seems that the problem happens when you deploy the .ear, you'll run into this class-loading problem. Have you had this problem?
Posted by: dontrango on July 24, 2005 at 12:49 AM
I am very glad that you got the example working.
Ah... The way to reproduce the problem you describe "CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken" is the following. Don't change anything in the application. Now, execute a query. In updated example, the query is "from Person" inside of the getPersons() method. Hibernate query uses ANTLR and so does WebLogic. ANTRL does Class.forName() instead of using the context class-loader. Therefore, you get the above exception.
There are at least two ways to solve this problem. One is to use the older query factory that does not use ANTLR. The second is to use put the patched version of ANTLR that ships with Hibernate. Put the patched version of ANTLR in the WebLogic PRE_CLASSPATH.
I updated to blog entry above to reflect this. Also, I updated the sample application to illustrate this as well.
Comments, questions, and feedback are most welcome...
Best regards,
+prakash
Posted by: pmalani on July 25, 2005 at 03:44 PM
I am glad you found the sample application useful. I hope you will share your experiences in integrating Spring. I will update my blog as well as the sample application with Spring support. So, please stay tuned...
Thanks for pointing out about getPerson2() method. This relies upon leveraging JNDI for session factory. Stay, tuned for my blog entry (very soon now) that talks about JNDI, JTA, JCA, and JMX. If you find any other anomalies, please don't hesitate to let me know...
Wishing you the best,
+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/)
Posted by: pmalani on July 28, 2005 at 03:01 PM
Posted by: sbellare on July 29, 2005 at 04:22 PM
Assuming all the set-up is done and the server is running, I use the Workshop Test Browser to test it. Open up the DomainManagerService.jws in Workshop and hit the play button. This will lauch the Workshop Test Browser with the following URL: http://localhost:7001/WebServiceProject/test/service/DomainManagerService.jws?.EXPLORE=.TEST You can always go directly to this URL in any browser. From here, I can test the methods of the web-serivce including getPerson() method.
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/)
Posted by: pmalani on August 01, 2005 at 03:43 PM
Posted by: rickyd on August 30, 2005 at 09:45 AM
Hibernate 2.x configuration will probably be very similar. What kinds of dev tools you are talking about?
Hibernate 3.x has been out for some time. I would highly recommend it versus 2.x.
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/)
Posted by: pmalani on August 30, 2005 at 03:23 PM
Posted by: rickyd on August 31, 2005 at 07:33 AM
Hey just wondering if you were going to also explain how to get Hibernate 3.0 working in Weblogic 9.0 in the future?
Thanks,
Mark WolfePosted by: markwolfe on October 03, 2005 at 10:31 PM
Posted by: eholmes2@cox.net on November 08, 2005 at 11:16 AM
Posted by: eholmes2@cox.net on November 08, 2005 at 03:59 PM
Posted by: drujensen on December 13, 2005 at 09:49 AM
Posted by: rkampli123 on March 16, 2006 at 03:14 AM
Posted by: rnmanhon on March 20, 2006 at 10:37 PM
Posted by: rnmanhon on March 20, 2006 at 10:53 PM
Posted by: rnmanhon on March 20, 2006 at 11:18 PM
Posted by: kihatti on April 19, 2006 at 10:43 PM
Posted by: jadeite100 on May 29, 2006 at 09:36 AM
Posted by: jadeite100 on May 29, 2006 at 09:41 AM
Posted by: jadeite100 on May 29, 2006 at 12:55 PM
If you put the jar in the server CLASSPATH, then it affects all the applications. I don't know of way to control so that it will only affect one application.
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/)
Java Enterprise in a Nutshell (http://www.oreilly.com/catalog/javaentnut3/)
Posted by: pmalani on June 02, 2006 at 07:21 PM
Posted by: sanjay_kumar.prabhakar@novartis.com on June 13, 2006 at 03:41 PM
Posted by: burakm on June 21, 2006 at 04:28 PM
Posted by: debashish_saha on July 20, 2006 at 12:14 AM
Posted by: manasshinde on July 21, 2006 at 01:08 AM
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 are listed in date ascending order (oldest first) | Post Comment
Posted by: sethatklipmart on August 17, 2005 at 09:06 AM
Posted by: robert.heise on October 13, 2005 at 05:55 PM
Posted by: rn056569 on November 16, 2005 at 05:24 PM
Posted by: SESHADRI on November 18, 2005 at 12:19 AM