hibernate不要用到ServiceRegistry对象吗?
hibernate不要用到ServiceRegistry对象吗?
hibernate不要用到ServiceRegistry对象吗?
2018-03-15
Hibernate使用ServiceRegistryBuilder出错
原因:版本4之后的Hibernate中buildServiceReguistry()方法被替换了。
解决方法:(1)版本导入更换为:
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
(2)在版本4中的用法:
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
(3)在版本5中的用法:
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
举报