关于hibernate API访问数据库创建服务注册对象问题
//创建注册对象
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
时报错:Type mismatch: cannot convert from ServiceRegistryBuilder to ServiceRegistry;
老师给的包缺少ServiceRegistry jar?换官网的4.2.21试试
//创建注册对象
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
时报错:Type mismatch: cannot convert from ServiceRegistryBuilder to ServiceRegistry;
老师给的包缺少ServiceRegistry jar?换官网的4.2.21试试
2017-04-12
// 1.生成配置对象(config)
Configuration config = new Configuration().configure();
// 2.生成服务注册对象:config.getProperties()-读取配置文件
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(config.getProperties()).buildServiceRegistry();
// 3.创建会话工厂对象
sessionFactory = config.buildSessionFactory(serviceRegistry);
// 4.得到会话对象
session = sessionFactory.openSession();// 开启会话得到会话对象
// 5.开启事务
transaction = session.beginTransaction();
举报