当前位置: 代码迷 >> J2EE >> hibernate4 -AnnotationConfiguration类过期解决思路
  详细解决方案

hibernate4 -AnnotationConfiguration类过期解决思路

热度:29   发布时间:2016-04-22 02:03:13.0
hibernate4 -----AnnotationConfiguration类过期
Java code
package com.user.util;import org.hibernate.SessionFactory;import org.hibernate.cfg.[del]AnnotationConfiguration[/del];public class HibernateUtil {    public static SessionFactory sessionFactory;    static {        try{        sessionFactory = new AnnotationConfiguration().configure().[del]buildSessionFactory();[/del]        }catch(Exception e){            e.printStackTrace();        }    }    public static SessionFactory getSessionFactory(){        return sessionFactory;    }}

 
AnnotationConfiguration在hibernate 4版本中过期 请问是用那个代替了 而且在hibernate 4中找不到 AnnotationConfiguration这个类。代码中的[del][del]代表删除线——

------解决方案--------------------
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sf = configuration.buildSessionFactory(serviceRegistry);
  相关解决方案