根据HIBERNATE的文档,HIBERANTE是无法帮定到TOMCAT的JNDI的。
因此你只能用那个ThreadLoal的方法
因此你只能用那个ThreadLoal的方法
解决方案 »
- 当name为对象.属性时,如何使用jQuery.validate框架验证注册表单
- hibernate读数据库float问题!谢谢
- 用poi和hibernate导出报表时碰到的奇怪现象
- Exception in thread "main" java.lang.ClassFormatError错误.
- spring2+struts2+sitemesh,关于sitemesh修饰框架的问题?
- myeclipse 下建立的web project 如何打包?
- 在XML流中怎样处理标记"<",">" 呢? (请指教方法)
- javamail写的一个bean出问题了!
- 请问,怎样对一个jar包进行数字签名?
- HTTP Status 500 - Filter execution threw an exception
- 急,快帮帮我,struts问题?
- JAVA录音程序调用
If you wish to have the SessionFactory bound to a JNDI namespace, specify a name (eg. java:comp/env/hibernate/SessionFactory) using the property hibernate.session_factory_name. If this property is omitted, the SessionFactory will not be bound to JNDI. (This is especially useful in environments with a read-only JNDI default implementation, eg. Tomcat.)
代码中也是openSession的时候报错了
sessionFactory = new Configuration().configure().buildSessionFactory();
...
session = sessionFactory.openSession();
错误信息:
信息: Not binding factory to JNDI, no JNDI name configured我就奇怪,没有用tomcat的jndi数据源,他怎么就去找jndi了呢?
难道这个不是使用hibernate.cfg.xml中配置的数据源吗?
session = sessionFactory.openSession();好像还有一个带参数的sessionFactory.openSession(conn);是不是可以给入一个数据连接,但现在的问题是我就根本到不了这一步,
在“sessionFactory = cfg.buildSessionFactory();”时就出错了。
你只能用文档里面的那个自己写程序管理SessionFactory的例子。
...
信息: Not binding factory to JNDI, no JNDI name configured
...
这一句是正常的,注意“信息”不是错误,错误是其他的地方,这里根本就没有错误
java.lang.ExceptionInInitializerError
at net.sf.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:26)
at net.sf.hibernate.examples.quickstart.TestHibernateUtil.setUp(TestHibernateUtil.java:12)
...(Click for full stack trace)...
Caused by: net.sf.hibernate.HibernateException: Could not find datasource
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1132)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:766)
at net.sf.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:23)
... 11 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
... 16 more
的时候出错,走不到下一步threadLocal.set(session);
页面显示:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Servlet execution threw an exception
root cause java.lang.NoClassDefFoundError: javax/transaction/Synchronization
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:313)
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:317)
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:330)
com.lis.framwork.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:63)
com.lipile.struts.action.LoginAction.execute(LoginAction.java:59)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
信息: building session factory
2004-11-26 15:41:50 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
信息: Factory name: foo
2004-11-26 15:41:50 net.sf.hibernate.util.NamingHelper getInitialContext
信息: JNDI InitialContext properties:{}
2004-11-26 15:41:50 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
信息: Bound factory to JNDI name: foo
2004-11-26 15:41:50 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
警告: InitialContext did not implement EventContext
这里是什么问题。