public class EjB3Configuration {
private Ejb3Configuration configuration = null;
protected PersistenceUnitInfo persistenceUnitInfo;
public Ejb3Configuration getConfiguration() {
synchronized(this) {
if (configuration == null) {
Ejb3Configuration temp = new Ejb3Configuration();
String previousValue = persistenceUnitInfo.getProperties().getProperty("hibernate.hbm2ddl.auto");
persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", "none");
configuration = temp.configure(persistenceUnitInfo, new HashMap());
configuration.getHibernateConfiguration().buildSessionFactory();
if (previousValue != null) {
persistenceUnitInfo.getProperties().setProperty("hibernate.hbm2ddl.auto", previousValue);
}
}
}
return configuration;
}
public PersistenceUnitInfo getPersistenceUnitInfo() {
return persistenceUnitInfo;
}
public void setPersistenceUnitInfo(PersistenceUnitInfo persistenceUnitInfo) {
this.persistenceUnitInfo = persistenceUnitInfo;
}
}
我对 ejb3 的调用如下所示。由于 ejb3 已从 4.3.10.Final hibernate 版本中删除,我如何将上述代码重构为实体管理器。
public PersistentClass getPersistentClass(final String targetClassName) {
return ejb3Configuration.getConfiguration().getClassMapping(targetClassName);
}
我的电话
最佳答案
要以编程方式创建EntityManagerFactory
,您可以这样做:
Properties properties = getProperties();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("myPersistenceUnit", properties);
关于java - 将ejb代码更改为EntityManager代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31230019/