Hibernate:无法解析符号beginTransaction

时间:2016-07-02 09:10:03

标签: java spring hibernate

我在我的演示项目中创建了这个hibernate配置类

phtml

然后我尝试从Customer类

启动会话
mport org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();
    private static ServiceRegistry serviceRegistry;

    private static SessionFactory buildSessionFactory() {
        Configuration configuration = new Configuration().configure();
        serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
//        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        return configuration.buildSessionFactory(serviceRegistry);
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void shutdown() {
        // Close caches and connection pools
        getSessionFactory().close();
    }

}

但我收到此错误

Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();

我在这里缺少什么?

0 个答案:

没有答案