我参照网上文章,做了如下配置,看起来正常,但就是无法得到SessionFactory。请高手过目,指点迷津:
1、在WebLogic的启动命令中将Hibernate有关的jar包全部加到CLASSPATH中
2、写一个启动类如下:
package util;
import weblogic.common.T3ServicesDef;
import weblogic.common.T3StartupDef;
import java.util.Hashtable;
import org.hibernate.cfg.Configuration;
public class HibernateStartup implements T3StartupDef {
public String startup(String string, Hashtable hashtable) throws Exception {
Configuration conf = new Configuration().configure();
conf.buildSessionFactory();
return "SessionFactory init complete and bound to JNDI successful";
}
public void setServices(T3ServicesDef t3ServicesDef) {
}
}
3、写一个hibernate.cfg.xml如下:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="jndi.mysource">
<property name="connection.datasource">jndi/mhwzlocal</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:8081</property>
</session-factory>
</hibernate-configuration>
4、将上面的两个文件编译后打包jndi-init.jar,也放入WebLogic的启动命令中的CLASSPATH。包中结构如下:
+ jndi-init.jar
- hibernate.cfg.xml
+ util
- HibernateStartup.class
5、启动WebLogic,配置好数据源jndi/mhwzlocal,加入Startup Class。
6、重新启动WebLogic,Hibernate初始化完毕,没有出错,但有一句警告:
2006-6-30 10:51:26 org.hibernate.impl.SessionFactoryObjectFactory addInstance
警告: InitialContext did not implement EventContext
7、检查JNDI Tree,jndi/mysource已经绑定了,这是WebLogic中查到的该JNDI的信息:
Bind Name: mysource
Object Class: org.hibernate.impl.SessionFactoryImpl
Object Hash Code: 34701006
Object To String: org.hibernate.impl.SessionFactoryImpl@2117ece
8、我并不清楚Hibernate调用该JNDI的时候配置文件该怎么写。我是这样写的:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:8081</property>
<mapping resource="pojos/person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
9、我试图通过查找JNDI获得SessionFactory,我的HibernateUtil是这样写的:
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
static {
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://127.0.0.1:8081");
Context ctx = new InitialContext(p);
sessionFactory = (SessionFactory) ctx.lookup("jndi/mysource");
} catch (Throwable ex) {
ex.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
10、运行结果是找不到SessionFactory,程序输出如下:
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - JNDI lookup: jndi/mysource
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - lookup: uid=4a45a8b20c22d912010c22d913490000
15 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory - Not found: 4a45a8b20c22d912010c22d913490000
15 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - {}
望高手指点迷津,不胜感激!
1、在WebLogic的启动命令中将Hibernate有关的jar包全部加到CLASSPATH中
2、写一个启动类如下:
package util;
import weblogic.common.T3ServicesDef;
import weblogic.common.T3StartupDef;
import java.util.Hashtable;
import org.hibernate.cfg.Configuration;
public class HibernateStartup implements T3StartupDef {
public String startup(String string, Hashtable hashtable) throws Exception {
Configuration conf = new Configuration().configure();
conf.buildSessionFactory();
return "SessionFactory init complete and bound to JNDI successful";
}
public void setServices(T3ServicesDef t3ServicesDef) {
}
}
3、写一个hibernate.cfg.xml如下:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="jndi.mysource">
<property name="connection.datasource">jndi/mhwzlocal</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:8081</property>
</session-factory>
</hibernate-configuration>
4、将上面的两个文件编译后打包jndi-init.jar,也放入WebLogic的启动命令中的CLASSPATH。包中结构如下:
+ jndi-init.jar
- hibernate.cfg.xml
+ util
- HibernateStartup.class
5、启动WebLogic,配置好数据源jndi/mhwzlocal,加入Startup Class。
6、重新启动WebLogic,Hibernate初始化完毕,没有出错,但有一句警告:
2006-6-30 10:51:26 org.hibernate.impl.SessionFactoryObjectFactory addInstance
警告: InitialContext did not implement EventContext
7、检查JNDI Tree,jndi/mysource已经绑定了,这是WebLogic中查到的该JNDI的信息:
Bind Name: mysource
Object Class: org.hibernate.impl.SessionFactoryImpl
Object Hash Code: 34701006
Object To String: org.hibernate.impl.SessionFactoryImpl@2117ece
8、我并不清楚Hibernate调用该JNDI的时候配置文件该怎么写。我是这样写的:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:8081</property>
<mapping resource="pojos/person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
9、我试图通过查找JNDI获得SessionFactory,我的HibernateUtil是这样写的:
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
static {
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://127.0.0.1:8081");
Context ctx = new InitialContext(p);
sessionFactory = (SessionFactory) ctx.lookup("jndi/mysource");
} catch (Throwable ex) {
ex.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
10、运行结果是找不到SessionFactory,程序输出如下:
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - JNDI lookup: jndi/mysource
0 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - lookup: uid=4a45a8b20c22d912010c22d913490000
15 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory - Not found: 4a45a8b20c22d912010c22d913490000
15 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory - {}
望高手指点迷津,不胜感激!
浙公网安备 33010602011771号