Web服务器上的HibernateUtil初始化错误
我有一个Web服务器,当我尝试使用hibernate util时,我得到一个expetion(返回到客户端): 它在我本地的电脑上运行得很好。我怎么知道它的原因是什么Web服务器上的HibernateUtil初始化错误,hibernate,Hibernate,我有一个Web服务器,当我尝试使用hibernate util时,我得到一个expetion(返回到客户端): 它在我本地的电脑上运行得很好。我怎么知道它的原因是什么 I have the following code: public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // Create the
I have the following code:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
// System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
我真的需要你的帮助。。。可以提供所需的任何代码
我已经更新了HibernateUtil,但没有使用try/catch,现在我得到了确切的提示:
SoapFault - faultcode: 'soapenv:Server' faultstring: 'org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;' faultactor: 'null' detail: org.kxml2.kdom.Node@4054b2c0
但是jar是部署的…根据我使用静态块初始化sessionFactory的经验,您的问题在于这行代码:
sessionFactory = new Configuration().configure().buildSessionFactory();
看起来在构建sessionFactory时无法获取数据源
您是否可以记录此行的异常取消注释并查看正在打印的内容:
System.err.println("Initial SessionFactory creation failed." + ex);
如何在主机中查看此日志?将尝试将ex放入客户端I获取以下内容:org.hibernate.hibernateeexception:/hibernate.cfg.xml未找到。为什么…?查看部署的jar,看看jar中是否有这个文件,通常应该在src folderWell下出现。。。不是,我该怎么加呢?我不知道你是怎么做的,ANT?您必须重新构建它,并确保在jar文件中添加hibernate.cfg。
System.err.println("Initial SessionFactory creation failed." + ex);