休眠可选连接
我有一个按照以下代码使用一对一映射的实体:
@Entity
@Table(name = "my_entity")
public class MyEntity
{
...
@OneToOne
@JoinColumn(name = "site_id")
private Site site;
...
}
我刚刚被告知必须开始存储具有“site_id”值的 MyEntity 条目,该值可能不存在于站点表中。我仍然需要存储“site_id”的值,但它与站点实体不匹配。
我唯一能想到的是创建映射到同一个表的第二种类型的实体,该实体不会在站点表上映射一对一/联接。
有没有办法在不为同一个表创建第二个映射对象的情况下执行此操作?
谢谢,保罗。
I have an entity mapped with a One-To-One as per the following code:
@Entity
@Table(name = "my_entity")
public class MyEntity
{
...
@OneToOne
@JoinColumn(name = "site_id")
private Site site;
...
}
I've just been told that I must start storing MyEntity entries with a value for 'site_id' which may not exist within the Site table. I still need to store the value for 'site_id' however it will not match a Site entity.
The only thing I can think of is to create a 2nd type of Entity mapped to the same table that doesn't map a One-To-One/join on the site table.
Is there a way to do this without creating a 2nd mapped object for the same table?
thanks, paul.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是非常糟糕的设计。外键应该是外键,并且不应该指向不存在的行。我会修复数据/设计。
如果您真的不能,请使用描述的 NotFound 注释 此处:
This is very bad design. A foreign key should be a foreign key, and should not point to non-existing rows. I would fix the data/design.
If you really really can't, use the NotFound annotation described here :