当我使用旧的弃用的hibernate方法构建会话工厂时,它工作正常:
SessionFactory sessionFactory = new Configuration()
.configure().buildSessionFactory();
当我用new方法替换它时,它被编译但在运行时得到未知实体异常,好像新方法没有拿起映射资源=" xyz.hbm.xml"属性:
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
// builds a session factory from the service registry
SessionFactory sessionFactory = `configuration.buildSessionFactory(serviceRegistry);`
我的问题是,我是否需要在配置中进行一些更改或在hibernate.cfg.xml文件中添加一些属性,以便在使用新方法构建会话工厂时读取和加载属性?< /强>
我也试过以下:
Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory sessionFactory = configuration .buildSessionFactory(serviceRegistry);