![](/img/trans.png)
[英]How to switch an Hibernate many-to-many relationship from xml to annotation based configuration?
[英]Migration from XML to Annotation configuration in Hibernate 4.2
我一直使用hibernate.cfg.xml來配置Hibernate。 由於各種原因,我需要將所有配置都移至Java,並且映射實體存在問題。
以前在XML中,我的映射如下所示:
<mapping class="com.mycompany.enitites.Test" />
一切都是注釋驅動的,因此我不需要指定其他任何內容。
現在,我使用Hibernate的Configuration.class
配置了所有內容,如何添加映射? 我嘗試了configuration.addClass(Test.class)
但這引發了一個錯誤,即文件test.hbm.xml
不存在。 而且我不想使用它,我希望Hibernate從注解中讀取映射。
編輯:我嘗試了configuration.addAnnotatedClass(Test.class)
但在涉及Test.class
實體的第一個遇到的查詢上,此引發relation "test" does not exist
。
我在以下幾行中犯了語法錯誤:
configuration.setProperty("hibernate.hbm2ddl.auto", "update");
這阻止了Hibernate在啟動時創建表並因此找不到它們...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.