Configure Hibernate 3.0 on WebLogic 8.1

Source: Internet
Author: User
Tags connection pooling rar

The following are the steps for configuring hibernate on WebLogic 8.1:

First, you create a domain. I created a weblogic Workshop (WLW) domain because I intend to use WLW to create and implement applications.

Add Hibernate...\lib\antlr-2.7.5h3.jar to Pre_classpath, or set the Query.factory_class property to user 2.x in Hibernate.cfg.xml file Query Factory.

The WLW domain also initiates a Pointbase database instance. I will use this built-in instance. I created a new user and schema. Some sample data has been populated for this pattern.

Configure connection pooling and data sources in the server instance.

Create the application. I'm going to use WebLogic workshop to create.

Where should libraries (jar files) (which are required for successfully running hibernate) be placed? Placed in the application's App-inf/lib folder. The library includes Hibernate.jar and additional third-party libraries. Table 3-1 referencing hibernate reference.

Create a Java project in WLW. The Java project includes a domain class that maps to a database. WLW compiles the project and puts the resulting jar files in the App-inf/lib directory. Encodes a domain class in a Java project. Create Hibernate mapping files and hibernate configuration files. In addition, the Hibenateutil class is created from the Hibernate reference replication implementation. The hibernate configuration file includes the Jndi name of the data source.

Create an EJB object (for example, a module). The project contains a session bean. Write a session bean that manipulates the domain class.

Create a Web or Web service project (for example, a module). This project contains components that are interoperable to test session beans.

A complete, valid, self-contained sample application is here. This includes the schema and all the hibernate configuration files.

I described the steps above to configure Hibernate 3.0 on WebLogic 8.1. The advanced configuration is described below, where Hibernate uses the WebLogic Java naming and directory interface (Java naming and directory Interface,jndi), the Java Transaction API (Java Transaction API,JTA), Java Connector architecture (Java Connector ARCHITECTURE,JCA), and Java Management extensions (Java Management extension,jmx) implementations.

Let's start with the Jndi first. Make Sessionfactory available in Jndi by naming sessionfactory,hibernate in the Hibernate.cfg.xml file. Ah! This does not work in the WebLogic. As described here, WebLogic Jndi does not work well with hibernate. There are multiple workspaces. The workspace manually binds sessionfactory to Jndi by WebLogic the startup class or by starting the servlet. However, I cannot make the Sessionfactory instance return from Jndi safely. So, compromise, add an accessor for 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 options: Org.hibernate.transaction.JTATransactionFactory and Org.hibernate.transaction.CMTTransactionFactory. The documentation suggests that the bean managed transaction definition (Bean Managed Transaction demarcation,bmtd) Bean uses jtatransactionfactory, and the container managed transaction is defined (Container Managed Transaction demarcation,cmtd) beans use cmttransactionfactory.

Jtatransactionfactory seems more general, and it supports both BMTD beans and cmtd beans. Therefore, I am configuring the jtatransactionfactory. In addition, in order to find transactions in a container-specific manner, I configured the Transaction.manager_lookup_class in the Hibernate.cfg.xml file. With this configuration, I do not need to use the Hibernatetransaction API at all.

The JCA support for hibernate is experimental in nature and is not yet fully applied to WebLogic. I can assume that later hibernate will be packaged as resource ARchive (RAR) files. The Hibernate RAR file is deployed as a resource adapter. The adapter makes the session available in Jndi. All configuration elements are configured through resource adapters (XML files), not by hibernate.cfg.xml files or by using other methods. Why do you want to configure Hibernate to use JCA in WebLogic? JCA is designed to encapsulate traditional system connections, transactions, and so on, and to make them available in Java EE. However, due to hibernate, the advantages of traditional resource adapters can not be fully reflected. Once the hibernate is configured as a resource adapter, the coupling of a particular application with the hibernate is weakened. Multiple different applications can use the same hibernate resource adapter. Because of the EJB 3.0 that is currently being developed, this configuration has a greater advantage over the standardization of the EJB Persistence API, Hibernate, and Java Data Objects (Java object,jdo). Theoretically, you can heat-deploy (or redeploy) adapters and change the persistence implementation.

The hibernate comes with a jmx Management Bean (MBean) implementation. I don't know how to use JMX to deploy Hibernate to WebLogic. What are the benefits of Hibernate and WebLogic using JMX? There are at least two articles. One is deployment and redeployment. A more important one is that you can monitor hibernate and the statistics you get. Running-time monitoring from the JMX console is the basic safeguard for the deployed application to run well.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.