开发时的环境配置如下:
写一个启动类加载和绑定hibernate的sessionfactory到weblogic下
代码如下:
public class hibernatestartup implements t3startupdef {
public static string config_file_path = "/hibernate.cfg.xml";
public void setservices(t3servicesdef services) {}
public static final string session_factory_jndi = "hibernate";
public static final string url = "t3://localhost:7001";
public string startup(string name, hashtable args) throws exception {
try {
dobind();
return "hibernate startup completed successfully";
} catch (exception e) {
}
return "hibernate startup completed successfully";
}
private static void dobind( ) throws exception
{
properties environment = null;
initialcontext context = null;
try
{
environment = new properties( );
environment.put( context.initial_context_factory,"weblogic.jndi.wlinitialcontextfactory");
environment.put( context.provider_url, url );
context = new initialcontext( environment );
configuration configuration = (new configuration()).configure(config_file_path);
sessionfactory factory = configuration.buildsessionfactory();
if (factory == null)
throw new exception("sessionfactory cannot be built?!");
try
{
if( context.lookup("hibernate")!= null )
{
context.rebind("hibernate", factory);
}
else
{
context.bind("hibernate", factory);
}
}
catch ( namingexception nameex )
{
nameex.printstacktrace();
context.bind("hibernate", factory );
}
}
catch ( namingexception nameexp )
{
throw new exception( "namingexception: " + nameexp.getmessage( ));
}
catch( exception excp )
{
throw excp;
}
}
static private initialcontext getinitialcontext() throws exception {
string url = "t3://localhost:7001";
properties properties = null;
try {
properties = new properties();
properties.put(context.initial_context_factory, "weblogic.jndi.wlinitialcontextfactory");
properties.put(context.provider_url, url);
return new initialcontext(properties);
}
catch(exception e) {
logger.fatal("unable to connect to weblogic server at " + url);
logger.fatal("please make sure that the server is running.");
throw e;
}
}
}
然后编译
在jbuilder2005的configserver下的calsspath下面加入这个类的所在路径,我的是c:/work/overstock/classes
然后把hibernate用到的jar文件也加入,就可以开发了。
部署的时候只要把这些路径加入到domain的startweblogic.cmd中就可以,不过要把c:/work/overstock/classes中的类打成jar包再加,要不weblogic会找不到的。
参考文章:http://www.hibernate.org/120.html
闽公网安备 35060202000074号