我试图在Java EE 6应用程序中运行架构更新。在之前的Hibernate版本中,我设法创建了一个Ejb3Configuration
,然后运行了SchemaUpdate。差不多是这样的:Hibernate中的程序架构更新4
Ejb3Configuration cfg = new Ejb3Configuration();
cfg.configure(PERSISTENCE_UNIT_NAME, null);
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
cfg.setProperty("hibernate.dialect", dialect.getClass().getName());
Collection<String> entityClassNames = getEntityClassNames(PERSISTENCE_UNIT_NAME);
for (String className : entityClassNames)
{
cfg.addAnnotatedClass(Class.forName(className));
}
EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
new SchemaUpdate(cfg.getHibernateConfiguration()).execute(true, true);
显然,类Ejb3Config
已被弃用,不支持。那么使用hibernate 4做一个SchemaUpdate的正确方法是什么?
看来你有麻烦了。根据[HHH-2578](https://hibernate.onjira.com/browse/HHH-2578),“配置”正在被['MetadataSources']替代(http://docs.jboss.org/hibernate/ orm/4.1/javadocs/org/hibernate/metamodel/MetadataSources.html)和朋友。目前我没有办法看到使用它来提供“SchemaUpdate”。我怀疑[HHH-6445](https://hibernate.onjira.com/browse/HHH-6445)是解决此问题的问题,但尚未解决,并且一年未触及。 –