一、首先需要把hibernate 用到的jar包和配置文件都放到weblogic能够搜索到的classpath路径上。单单这一步就有很多人很迷茫,其实去仔细看看weblogic的启动脚本文件startweblogic.cmd和startwls.cmd,我想大部分人都知道该怎么配置了。
我机器上的有个hibernate的项目,在d:\test\oracle目录下,该目录下的结构是:
d:\test\oracle\lib 放置hibernate的所有jar包
d:\test\oracle\src 放置源代码
d:\test\oracle\classes 编译好的代码和hibernate的配置文件(hibernate.properties, log4j.properties, cache.ccf)
现在需要把d:\test\oracle\lib目录下那些jar文件和d:\test\oracle\classes目录都放置到weblogic的 classpath里面去,所以修改mydomain里面的weblogic启动脚本startweblogic.cmd,在启动weblogic之前,插入设置classpath的命令,如下:
| @rem set hibernate classpath set hibernate_lib=d:\test\oracle\lib set hibernate_classes=d:\test\oracle\classes set classpath=%classpath%;%hibernate_lib%\cglib-asm.jar;%hibernate_lib%\commons-beanutils.jar; %hibernate_lib%\commons-collections.jar;%hibernate_lib%\commons-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%; |
| @rem call weblogic server call "c:\bea\weblogic700\server\bin\startwls.cmd" |
| hibernate.dialect.net.sf.hibernate.dialect.oracledialect hibernate.connection.datasource mypool 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 |
| package com.javaeye; import java.util.hashtable; import weblogic.common.t3startupdef; import weblogic.common.t3servicesdef; import.net.sf.hibernate.cfg.configuration; import.net.sf.hibernate.sessionfactory; 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"; } } |
| sessionfactory sf = new configuration().configure().buildsessionfactory(); |
| bind name: hibernate object class:.net.sf.hibernate.impl.sessionfactoryimpl object hash code: 454492 object to string:.net.sf.hibernate.impl.sessionfactoryimpl@6ef5c |
| context ctx = new initialcontext(); sessionfactory sf = (sessionfactory) ctx.lookup("hibernate/session_factory"); |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器