在java的hibernate框架中获取当前会话的困难
我在使用以下语句获取当前会话时遇到问题- 会话会话=HibernateUtil.getSessionFactory().getCurrentSession() 我的HibernateUtil类具有以下代码-在java的hibernate框架中获取当前会话的困难,java,hibernate,Java,Hibernate,我在使用以下语句获取当前会话时遇到问题- 会话会话=HibernateUtil.getSessionFactory().getCurrentSession() 我的HibernateUtil类具有以下代码- public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { sessionFactory = ne
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
我的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>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:anu</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">abc</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="hbm/Userinfo.hbm.xml"/>
<mapping/> </session-factory> </hibernate-configuration>
org.hibernate.dialen.oraclealent
oracle.jdbc.OracleDriver
jdbc:oracle:thin:@localhost:1521:anu
管理
abc
真的
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
线
您面临的问题到底是什么?如果您遇到编译/运行时错误,请将其发布到Session Session=HibernateUtil.getSessionFactory().getCurrentSession();语句未引发任何异常。我从一个Servlet调用它,当它遇到这个语句时,Servlet就停止了。这可能是它第一次尝试打开到数据库的连接。您的数据库是否有可能具有某种maxConnections属性,或者在尝试打开连接时阻止了Hibernate?如果没有异常,并且您确定没有以某种方式忽略/隐藏异常,那么您很可能会像@Pace建议的那样被阻止,或者遇到某种形式的死锁。您应该能够使用IDE进行调试并暂停线程,以查看其“停止”的确切位置。您的本地计算机(@localhost:1521)中是否运行oracle服务器?如果是这样,您可以检查V$会话,查看连接是否真正建立起来。