Play框架onetoone删除引用完整性
我遇到 JUnit 测试的引用完整性约束违规。使用 playframework 和我的两个实体如下。
@Entity
public class User extends Model{
public String email;
public String password;
@OneToOne(mappedBy="user",cascade=CascadeType.ALL)
public Patent patent;
}
@Entity
public class Patent extends Model{
@OneToOne
public User user;
}
在我的 Junit 测试中,以下行失败了
User.findById(user.id)._delete();
Referential integrity constraint violation: "FK340C82E547140EFE: PUBLIC.PATENT FOREIGN KEY(USER_ID) REFERENCES PUBLIC.USER(ID)"; SQL statement:
delete from User where id=? [23003-149]
谢谢
I get a referential integrity constraint violation for a JUnit Test. Using playframework and my two entities are as follows.
@Entity
public class User extends Model{
public String email;
public String password;
@OneToOne(mappedBy="user",cascade=CascadeType.ALL)
public Patent patent;
}
@Entity
public class Patent extends Model{
@OneToOne
public User user;
}
In my Junit test the following line fails
User.findById(user.id)._delete();
Referential integrity constraint violation: "FK340C82E547140EFE: PUBLIC.PATENT FOREIGN KEY(USER_ID) REFERENCES PUBLIC.USER(ID)"; SQL statement:
delete from User where id=? [23003-149]
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只能对关系的所有者使用一个 @OneToOne 注释。在您的情况下,用户拥有该专利,因此您可以从您的专利实体中删除以下内容:
再次尝试删除。
You should only use one @OneToOne annotation on the owner of the relationship. In your case the user owns the patent so you can remove the following from your Patent entity:
Try this with delete again.