难以在java中的hibernate框架中获取当前会话

时间:2013-03-24 16:00:20

标签: java hibernate

我在使用以下语句获得当前的热情时遇到了问题 -

  

Session session = 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>

0 个答案:

没有答案