struts1.1+weblogic7.0+hibernate2.02的問題
我將SessionFactory bind到wls的jndi樹上,在web層(struts的plugin中)可以lookup到,但在ejb層卻loopup 不到,我的程式碼如下:
//將 SessionFactory繫結到wls的jndi上
private static void initSessionFactory() throws HibernateException{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
try {
if (context == null) {
context = getInitialContext();
}
context.bind(GlobalNames.SESSION_FACTORY, sf);
}
catch (NamingException ex) {
System.out.println("init SessionFactory failed! ");
}
}
//這個方法使用weblogic的datasource,來返回session
public static Session getSession() throws HibernateException {
Connection conn = null;
SessionFactory factory = null;
try {
conn = DBUtil.getConnection();
}
catch (NoConnectionException ex) {
}
try {
if (context == null) {
context = getInitialContext();
}
factory = (SessionFactory) context.lookup(GlobalNames.SESSION_FACTORY);
}
catch (NamingException ex1) {
}
if(factory == null)
System.out.println("Can't lookup SessionFactory form jndi tree");
Session session = factory.openSession(conn);
return session;
}
//在struts的plugin中用上述的getSession方法是可以lookup到的,也可以返回session
private void initSF() {
NJSSSF sf = new NJSSSF();
try {
sf.init();
Session s1 = sf.getSession();
System.out.println("get session from plugin :(1)- " + s1.toString());
s1.close();
}
catch (HibernateException ex) {
if(GlobalNames.DEBUG_OUTPUT_FLAG){
System.out.println(ex.toString());
}
}
}
但在ejb層用getSession()方法卻找不到繫結在wls jndi 上的SessionFactory,但卻可以lookup到ejb,請高手指教?
//將 SessionFactory繫結到wls的jndi上
private static void initSessionFactory() throws HibernateException{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
try {
if (context == null) {
context = getInitialContext();
}
context.bind(GlobalNames.SESSION_FACTORY, sf);
}
catch (NamingException ex) {
System.out.println("init SessionFactory failed! ");
}
}
//這個方法使用weblogic的datasource,來返回session
public static Session getSession() throws HibernateException {
Connection conn = null;
SessionFactory factory = null;
try {
conn = DBUtil.getConnection();
}
catch (NoConnectionException ex) {
}
try {
if (context == null) {
context = getInitialContext();
}
factory = (SessionFactory) context.lookup(GlobalNames.SESSION_FACTORY);
}
catch (NamingException ex1) {
}
if(factory == null)
System.out.println("Can't lookup SessionFactory form jndi tree");
Session session = factory.openSession(conn);
return session;
}
//在struts的plugin中用上述的getSession方法是可以lookup到的,也可以返回session
private void initSF() {
NJSSSF sf = new NJSSSF();
try {
sf.init();
Session s1 = sf.getSession();
System.out.println("get session from plugin :(1)- " + s1.toString());
s1.close();
}
catch (HibernateException ex) {
if(GlobalNames.DEBUG_OUTPUT_FLAG){
System.out.println(ex.toString());
}
}
}
但在ejb層用getSession()方法卻找不到繫結在wls jndi 上的SessionFactory,但卻可以lookup到ejb,請高手指教?
相關文章
- 一個非技術問題的問題
- Spring的問題,還是Tomcat的問題SpringTomcat
- iptables的問題
- sqlldr的問題SQL
- ServerSocket的問題Server
- 問題的核心
- jbuilderx的問題!!!UI
- localhost的問題???localhost
- Bitmap的問題
- CUDA的問題
- 專案中常問的問題
- 【問題解決】單機搭建dataguard的問題
- 解決Redmine建立&更新問題時很慢的問題
- 解決問題的方法和途徑-問題管理
- 請教個問題執行 httprunner 遇到的問題HTTP
- 詢問面試官的面試問題面試
- python訪問redis的問題PythonRedis
- MySQL訪問受限的問題分析MySql
- 板橋老大,問個工作的問題
- 急問:mysql出現的問題MySql
- flutter的代理問題Flutter
- vue的SEO問題Vue
- webpack碰到的問題Web
- 快取的問題快取
- Redis中的問題Redis
- javascript的this指向問題JavaScript
- 工作遇到的問題
- Observer模式的問題Server模式
- Jive的NullPointException問題NullException
- Jbuilder的配置問題?UI
- session的存取問題Session
- 安裝的問題
- 求助,castor的問題AST
- JSF的問題JS
- jsp 的問題JS
- DDD的理解問題
- mysql的中文問題MySql
- 面試官問的2個棘手的問題面試