0

我在使用以下语句获取当前会话时遇到问题-

会话会话=HibernateUtil.getSessionFactory().getCurrentSession();

我的 HibernateUtil 类具有以下代码-

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>
4

0 回答 0