java - hibernate 一对一双向不工作

标签 java hibernate one-to-one bidirectional

我试图使我的代码具有双向关系(一对一),但显然代码无法正常工作。

这是头等舱。

public class User {


    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_PROFILE_FK")
    private UserProfile userProfile;

    //Accessor methods and other stuff
}

这是第二节课

@Entity
@Table(name ="USER_PROFILE")
public class UserProfile{


    @OneToOne(mappedBy="UserProfile")
    private User user;
    //Accessor methods
}

现在当我运行我的代码时会出现这个异常错误

Unknown mappedBy in: org.test.myApp.User, referenced property unknown: org.test.myApp.User.UserProfile

最佳答案

关联另一端的字段名为userProfile,而不是UserProfile,因此mappedBy 属性必须设置为userProfile

关于java - hibernate 一对一双向不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16073451/

相关文章:

java - 如何通过 Java 中的 Socket 编程将 post 数据(包含 2 个参数)发送到 https 服务器

spring - Hibernate 4.3-final 是否会导致 GooGooStatementCache 乘以准备好的语句?

java - 加密 Hibernate 中的特定列 : What to do with existing data and how to correctly implement @ColumnTransformer?

java - hibernate 中的一对一关系

java - org.hibernate.MappingException : Could not determine type for: (foo)

java - GlassFish 3.1 问题与/faces/*

java - 捕获当前线程的执行者

java - 如何使用 Spring-data-mongodb 根据月份对日期进行分组并获取每个月的最新值?

java - HQL 查询中的语法错误

java - 删除一对一 : Hibernate 3 + Spring 3 + PostgreSQL 9. 1