Integration of Weblogic81 and Hibernate

Source: Internet
Author: User

After a day, I finally completed the integration and installation of Hibernate and Weblogic81. Online materials are more or less involved, but they are incomplete and detailed. This article has written this article by referring to the article of the java sight Forum Moderator and the article on the hibernate website, hoping to help beginners of Hibernate.

Assume that your project is D: estprj; Destprjlib to store all jar files under the lib of Hibernate; D; estprjclasses to store all class files, specifically, it includes a weblogic startup class file dedicated to setting up the sessionfactory of hibernate, and hibernate. propties, log4j. properties, cache. ccf, oscache. properties: four configuration files;

D: eaweblogic81

1. The first step is to modify and configure the weblogic startup environment and add the lib and class directories of hibernate to the classpath environment of weblogic. The specific practices are as follows:
Find D: eauser_projectsdomainsmydomainstartWebLogic.cmd and add the following red font code to the file:

set SERVER_NAME=caserver
set CLASSPATH=%WEBLOGIC_CLASSPATH%;%POINTBASE_CLASSPATH%;
        %JAVA_HOME%jrelibt.jar;%WL_HOME%serverlibwebservices.jar;%CLASSPATH%
@rem set hibernate classpath
set HIBERNATE_LIB=Destprjlib
set HIBERNATE_CLASSES=Destprjclasses
set CLASSPATH=%HIBERNATE_LIB%cglib-asm.jar;%HIBERNATE_LIB%cglib-full-2.0.1.jar;%HIBERNATE_LIB%ehcache-0.7.jar;%HIBERNATE_LIB%commons-beanutils.jar;%HIBERNATE_LIB%commons-logging-1.0.3.jar;%HIBERNATE_LIB%commons-collections-2.1.jar;%HIBERNATE_LIB%commons-lang.jar;%HIBERNATE_LIB%commons-logging.jar;%HIBERNATE_LIB%dom4j-full.jar;%HIBERNATE_LIB%jcs.jar;%HIBERNATE_LIB%log4j-1.2.8.jar;%HIBERNATE_LIB%odmg.jar;%HIBERNATE_LIB%dom4j-1.4.jar;%HIBERNATE_LIB%hibernate2.jar;%HIBERNATE_CLASSES%;%CLASSPATH%

@REM Call WebLogic Server


Note that some netizens on the Internet may also have spaces or line breaks after adding jar files, and winrar and weblogic cannot be used to start normally. Therefore, it is best to set CLASSPATH to finish one line, similarly, the jar file name must be consistent with the jar file of hibernate. Otherwise, when weblogic is started, no class not found can be found.

2. Use the weblogic console to configure a jdbc pool. The database I use is sybase and a datasource. Of course, the datasource must start with the jdbc pool. Let's assume that its jndi name is misdb.

3. modify the hibernate configuration file. The hibernate configuration file contains two hibernate. propties and hibernate. cfg. xml. The first one is the default initialization environment file called after hibernate is started, and the last one is the file that can be dynamically adjusted. For example, the ing file for adding data tables and how to add code can be found online, I will not repeat it here. One of the two configuration files will work. During hibernate initialization, we will help hibernate to the weblogic jndi. We can describe it in the weblogic startup class source code in Step 4.

The configuration of the hibernate. propties file is relatively simple, and many database parameters have been annotated. It's cool.

Here we will use the weblogic data source misdb.

Make sure that the following code is unique.

## HypersonicSQL
#hibernate.dialect net.sf.hibernate.dialect.HSQLDialect
#hibernate.connection.driver_class org.hsqldb.jdbcDriver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:hsqldb:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test
#hibernate.connection.url jdbc:hsqldb:.

The green code must be commented out with the # symbol.

hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
hibernate.connection.datasource misdb
hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
hibernate.session_factory_name hibernate.session_factory
hibernate.jdbc.fetch_size 50
hibernate.jdbc.batch_size 25

Add the red code. Note that there may be corresponding parameter configurations later. Remember to comment it out.

Rest assured that the attachment will contain code

Okay. After the file is configured, remember to go to the d: estprjclasses directory;

4. There is no way to compile the weblogic startup source program. Because weblogic is special, we can only establish the sessionfactory of hibernate in this way. Why?
The JNDI implementation in WebLogic Server does not appear to support the Referenceable interface, and exhibits some rather strange behaviour when binding Serializable objects.

The two key statements in the Code are:

Configuration cfg = new Configuration();
SessionFactory factory = cfg.buildSessionFactory();

Some articles on the Internet are not correct, some are directly mapped to object classes, such as cat classes, and some are used

Configuration cfg = new Configuration().configure();
Remember to use the hibernate. cfg. xml file for configuration.

I think these two statements are the simplest, And I directly call hibernate. propties parameters; Code can, and below are also available. during compilation, ant must be used for compilation and how to configure ant. As mentioned in many articles on the internet, I will not talk much about it. Set WLSstartup. put java in D: hibernate21srcetsfhibernate, and then run ant or build in the command line. bat batch file, compiled WlSstartup. the class is probably in the D: hibernate21uild directory, and then copy it to d: estprjclasses.

Okay, complete

5. Configure the WlSstartup class in the weblogic console. how to configure it? robbin articles or any articles about weblogic management configuration are available. I will not mention them here.

All the precautions are completed. Start weblogic. It should be normal information, as long as you follow my steps, no problem.

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.