我一直在使用SchemaUpdate工具在控制檯改變什麼表/創建顯示主要方法,它在我的Hibernate項目順利進行:如何將Hibernate SchemaUpdate類與JPA persistence.xml一起使用?
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文件(在JPA規範中指定的META-INF目錄中自動檢測)。
我想這個問題太簡單改編,
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
但是,除此之外失敗。
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
有沒有人做到這一點? 謝謝。
在遊戲框架,我用Ejb3Configuration getHibernateConfiguration(),我得到「沒有提供數據源」。我如何提供連接(DB.datasource.getConnection())? – 2013-07-16 14:13:01