我在版本3.6.0中使用Hibernate,并且AnnotationConfiguration被标记为已弃用。
以下是我的HibernateUtil.java类中的行:
sessionFactory = new AnnotationConfiguration().configure("/hib.cfg.xml").buildSessionFactory();
AnnotationConfiguration的替代品是什么?
答案 0 :(得分:36)
“所有功能都已移至配置”: http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/AnnotationConfiguration.html
这是配置:
http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/Configuration.html
答案 1 :(得分:4)
就这样做
import org.hibernate.cfg.Configuration;
然后更改此代码
sessionFactory = new Configuration().configure("/hib.cfg.xml").buildSessionFactory();
答案 2 :(得分:2)
我使用此代码:
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);
答案 3 :(得分:1)
是的,这对我有用 -
Configuration cfg=new Configuration();
cfg.configure();
ServiceRegistry serviceregistry=new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
Session session=cfg.configure().buildSessionFactory(serviceregistry).openSession();