【发布时间】:2010-04-15 12:41:57
【问题描述】:
我有一个使用 SchemaUpdate 在控制台上显示要更改/创建的表的主要方法,它在我的 Hibernate 项目中运行良好:
public static void main(String[] args) throws IOException {
//first we prepare the configuration
Properties hibProps = new Properties();
hibProps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("jbbconfigs.properties"));
Configuration cfg = new AnnotationConfiguration();
cfg.configure("/hibernate.cfg.xml").addProperties(hibProps);
//We create the SchemaUpdate thanks to the configs
SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
//The update is executed in script mode only
schemaUpdate.execute(true, false);
...
我想在 JPA 项目中重用这段代码,没有 hibernate.cfg.xml 文件(也没有 .properties 文件),但有一个 persistence.xml 文件(在 META-INF 目录中自动检测到JPA 规范)。
这个太简单的改编我试过了,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
但它因该异常而失败。
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
有人做过吗? 谢谢。
【问题讨论】:
标签: hibernate jpa persistence.xml