bla*_*sei 7 java spring hibernate interface java-ee
我正在开发一个应用程序,其中所有的pojos都作为接口公开,但我们映射真实的实现类.我们正在使用spring和JPA annotation.i'm即将测试一对一的关系,我有一个光界面问题.
引起:org.springframework.beans.factory.BeanCreationException:在类路径资源[META-INF/model-config.xml]中定义名称为'sessionContainer'的bean时出错:
在设置构造函数参数时无法解析对bean'sessionFactory'的引用; 嵌套异常是org.springframework.beans.factory.BeanCreationException:
在类路径资源[META-INF/model-config.xml]中定义名称为'sessionFactory'的bean时出错:
init方法的调用失败; 嵌套异常是org.hibernate.AnnotationException:
@OneToOne或@ManyToOne在com.mycompany.project.subproject.model.UserAccountImpl.profile上引用了一个未知实体: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>
Run Code Online (Sandbox Code Playgroud)
这是两个涉及的类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;
....
}
Run Code Online (Sandbox Code Playgroud)
我仍然不是很舒适与Hibernate又那么我想知道如果我应该改变的UserProfile参考UserAccountImpl,以UserProfileImpl再次.那么同样可以在发生UserProfileImpl的userAccount参考,因为它是一个双向导航的东西.什么是不破坏结构一致性的最佳选择?感谢您阅读本文
您可以尝试以下操作:
@OneToOne(mappedBy="profile", targetEntity=UserAccountImpl.class)
private UserAccount userAccount
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8339 次 |
| 最近记录: |