First, first you need to put the JAR package and configuration files that Hibernate and the configuration files can search on the ClassPath path that you can search. There are many people who are very confused in single single, in fact, take a closer look at WebLogic Startweblogic.cmd and Startwls.cmd, I think most people know how to configure it. I have a hibernate project on the machine, in the D: / Test / Oracle directory, the structure in this directory is: D: / test / oracle / lib places all the JAR package for Hibernate
D: / test / oracle / src placement source code
D: / Test / Oracle / Classes Compile Code and Hibernate Profile (Hibernate.properties, Log4j.properties, Cache.ccf)
Now you need to put the D: / Test / Oracle / Lib directory, those JAR files and d: / test / oracle / classes directory are placed inside WebLogic's classpath, so modify the WebLogic startup script startweblogic.cmd in Mydomain, start WebLogic Before, insert the command to set the classpath, as follows: @Rem Set Hibernate ClassPath
SET HIBERNATE_LIB = D: / TEST / ORACLE / LIB
SET HIBERNATE_CLASS = D: / TEST / ORACLE / CLASSES
Set classpath =% classpath%;% hibernate_lib% / cglib-asm.jar;% hibernate_lib% / commons-beanutils.jar;
% Hibernate_lib% / commons-collections.jar;% hibernate_lib% / commns-lang.jar;
% Hibernate_lib% / commons-logging.jar;% hibernate_lib% / dom4j-full.jar;
% Hibernate_lib% / hibernate2.jar;% hibernate_lib% / jcs.jar;
% Hibernate_lib% / log4j-1.2.8.jar;% hibernate_lib% / odmg.jar;
% Hibernate_lib% / jta.jar;% hibernate_classes%;
Below, it is the start command inside the script: @Rem Call WebLogic Server
Call "c: /bea/weblogic700/server/bin/startwls.cmd"
Second, configure the connection pool of the Oracle database on WebLogic. This step is not related to hibernate, but if you want to use EJB, you want to use JTA, you must use the connection pool provided by WebLogic, and you cannot use the Hibernate's connected pool, or other third-party connecting pools, otherwise the container will not Manage database transactions. This step is very simple, just configuring connections pool and txdata source in WebLogic Console, my TXDataSource Take the name "MyPool" three, modify hibernate.properties. Use WebLogic connection pool instead of your own connection pool. I modified D: / Test/oracle/classes/Hibernate.properties, increased as follows: hibernate.diaract net.sf.hibernate.diaALect.OraclediaLect
Hibernate.Connection.DataSource MyPool
Hibernate.connection.Provider_class net.sf.hibernate.Connection.DataSource.Session_Factory_Name Hibernate.Session_Factory
Note the last row, this is the name that uses hibernate to bind JNDI to JNDi, which should be hibernate / session_factory, but WebLogic requires a change to. Number, but in the program, you still have to write hibernate / session_factory to mention one point Hibernate.jdbc.Fetch_size 50
Hibernate.jdbc.batch_size 25
There is a great performance impact on database queries and inserts, and the two options can be used to get the best performance. In order to ensure the pre-creation of the sessionFactory instance, create a Startup class using WebLogic T3StartUpDef interface, run when WebLogic is started: package com.javaeye;
Import java.util.hashtable;
Import WebLogic.common.t3startupdef;
Import WebLogic.common.t3ServicesDef;
Import Net.sf.hibiBernate.cfg.configuration;
Import Net.sf.hibActory;
Public Class HibernateStartup Implements T3StartUpdef {
Public void setservices (T3ServicesDef Services) {}
Public String Startup (String Name, Hashtable Args) Throws Exception {
SESSIONFACTORY SF = New Configuration (). Configure (). BuildSessionFactory ();
Return "Hibernate Startup Completed SuccessFully";
}
}
The code is very simple, in fact, it is to ensure pre-run sessionFactory sf = new configuration (). BuildSessionFactory ();
Create sf, and Hibernate will call a range of ways to bind the sf to the Hibernate / Session_Factory path under WebLogic JNDI tree. 4. When compiling HibernateStartup.java Compiles this source code, you should pay attention to import WebLogic.jar packets and Hibernate all related packages and configuration files. I put this source code in the D: / Test / Oracle / src directory, and I have compiled it with the Ant script that has already prepared it early and compiled. The compiled class file is placed to D: / Test / Oracle / Under the class directory, this directory has been added to the ClassPath of WebLogic, so it is very much. 5. Configure the Startup class to start WebLogic, open the Console console, find Startup & Shutdown on the Applet tree, then click "Configure a new startup class ...", in the name box, fill in the ClassName The Startup class you wrote, I fill in is com.javaeye.hibernateStartup, then click "Apply". Then switch to the Target this tab, select "MyServer" in the Avaiable box on the left of Target-Server, click the right arrow, move it to the "chosen" box on the right, and finally click on the "Apply" button. If there is no error message in WebLogic's DOS window, it should have been configured. 6. Now close WebLogic, re-run Startwelogic.cmd, start WebLogic, observe the output information of the DOS window, you can see the scroll output of Hibernate's initialization information, which proves that it has been configured. Now open the Console console, click Servers | MyServer in the left Applet tree, then find "View JNDi Tree" on the right side, click on it, open a browser window, display the JNDI tree, then you can see it A JNDI object named hibernate, click on it on the Applet tree on the left, look at the details, the information on my machine is as follows: bind name: hibernateObject class: net.sf.hibernate.Impl.SessionFactoryImpl
Object Hash Code: 454492
Object to string: Net.sf.hibernate.impl.SessionFactoryImpl@6ef5c
Completely correct! Finally, you can use JND to find sessionFactory with JND in EJB or Servlet / JSP. For example: context ctx = new initialContext ();
SessionFactory sf = (sessionFactory) ctx.lookup ("Hibernate / session_Factory);