【发布时间】:2015-01-28 03:22:08
【问题描述】:
@Entity
@Table(name = "users")
public class User extends Model
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Long id;
@OneToOne(mappedBy= "user", cascade = {CascadeType.ALL})
@JoinColumn(name="info_id",referencedColumnName = "id")
public Info info;
}
@Entity
@Table(name="infos")
public class Info extends Model
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Long id;
@OneToOne(mappedBy="info",cascade = {CascadeType.ALL})
@JoinColumn(name="user_id", referencedColumnName = "id")
public User user;
}
在我的迁移中,users 表包含一个 bigint 类型的 info_id 列,infos 表包含一个 bigint 类型的 user_id 列。
但是,当我运行应用程序时,它给了我PersistenceException: Error with the Join on [models.Info.user]. Could not find the matching foreign key for [id] in table[users]? Perhaps using a @JoinColumn with the name/referencedColumnName attributes swapped?
谁能提供一些关于我的代码有什么问题以及如何修复它的见解?谢谢。
【问题讨论】:
-
你可以为这两个表发布你的架构吗?
-
删除两个实体中的 mappedBy
-
否不要删除两个实体中的 mappedBy;从一侧取下它。它用于将关系标记为双向,并且只放在非所有者方面。
标签: jpa model-view-controller playframework playframework-2.0