我正在開發一個應用程序,其中所有的pojos都作爲接口公開,但我們映射了真正的實現class.we使用spring和JPA annotation.i'm來測試一對一的關係,並且我在界面上遇到了一個小問題。Hibernate與interface.i的一對一映射需要建議
造成的:org.springframework.beans.factory.BeanCreationException:錯誤創建名稱爲豆 'sessionContainer' 在類路徑資源定義[META-INF /模型-config.xml中]:
無法解析參考當設置構造函數參數時,bean'sessionFactory';嵌套異常是org.springframework.beans.factory.BeanCreationException:
在類路徑資源[META-INF/model-config.xml]中定義名稱爲'sessionFactory'的Bean時出錯:
調用init方法失敗;嵌套異常是org.hibernate.AnnotationException:
com.mycompany.project.subproject.model.UserAccountImpl.profile @OneToOne或@ManyToOne引用未知實體:com.mycompany.project。
所以這個類之前的所有其他類映射是否按預期工作,所以我將只發布applicationContext
文件我命名爲model-config.xml
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
...
<value>com.mycompany.project.subproject.model.UserProfileImpl</value>
<value>com.mycompany.project.subproject.model.UserAccountImpl</value>
...
</list>
</property>
這裏的一部分是兩個所涉及的類UserProfileImpl.java
和UserAccountImpl.java
//UserAccountImpl Class
@Entity
@Table(name ="USER_ACCOUNT")
public class UserAccountImpl implements UserAccount {
@Id @GeneratedValue
@Column(name="USER_ACCOUNT_ID")
private Long ID;
...
@OneToOne
@JoinColumn(name="USER_PROFILE_ID")
private UserProfile profile;
...
}
//UserProfileImpl class
@Entity
@Table(name="USER_PROFILE")
public class UserProfileImpl implements UserProfile {
@Id @GeneratedValue
@Column(name="USER_PROFILE_ID")
private Long ID;
....
@OneToOne(mappedBy="profile")
private UserAccount userAccount;
....
}
我還是不是很舒適與休眠尚未所以我不知道我是否應該在UserAccountImpl
更改UserProfile
參考UserProfileImpl
。然後又同樣可以在UserProfileImpl
發生了userAccount
參考,因爲它是一個雙向導航的東西。 什麼是不會破壞結構一致性的最佳選擇? 感謝您閱讀本
你能否闡述一下爲什麼你正在使用POJO的接口? – dlinsin 2009-11-09 13:03:33
Hibernate不可能知道你需要哪個類來實現'UserAccount',因此你必須使用像'@david'這樣的'targetEntity',因爲Hibernate不能推斷出這個。 – 2009-11-10 05:46:13