【问题标题】:Unknown mappedBy in hibernate OneToOne relationship休眠 OneToOne 关系中的未知 mappedBy
【发布时间】:2017-06-08 21:11:37
【问题描述】:

这是关于 Hibernate 在创建两个对象之间的 OneToOne 关系时引发的未知 mappedBy 异常的另一个问题。

据我了解,这两个对象之一需要 mappedBy 来声明表是通过第二个表的主键连接的。

此映射声明需要存在于包含外键的表上。

基于此,这里有两个类

@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "second")
public class Second implements Serializable{


    @OneToOne(cascade= CascadeType.ALL)
    @JoinColumn(name="first_id")
    First first;


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "first")
public class First implements Serializable{

    @OneToOne(mappedBy="first")
    Second second;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id;

}

这会引发异常

Unknown mappedBy in: First.second, referenced property unknown: Second.first

我错过了什么?

【问题讨论】:

  • 您是否在persistence.xml 中声明了实体类?你能发帖persistence.xml吗?
  • 我使用的是 dropwizard 框架,所以我没有配置 XML

标签: mysql hibernate dropwizard one-to-one


【解决方案1】:

我没有在应用程序类中使用 Hibernate Bundle 实例注册类

【讨论】:

    猜你喜欢
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2011-08-15
    • 2013-04-13
    • 1970-01-01
    • 2011-02-13
    相关资源
    最近更新 更多