使用@Where子句进行Hibernate @OneToOne映射 [英] Hibernate @OneToOne mapping with a @Where clause

查看:553
本文介绍了使用@Where子句进行Hibernate @OneToOne映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Will this work -

@OneToOne()
@JoinColumn(name = "id", referencedColumnName = "type_id")
@Where(clause = "type_name = OBJECTIVE")
public NoteEntity getObjectiveNote() {
  return objectiveNote;
}

这就是我想要做的 - 从表 note 其中 type_id 是当前对象的 id ,而 type_name OBJECTIVE

This is what I am trying to do - get the record from table note whose type_id is the id of the current object and type_name is OBJECTIVE.

我无法获得上述映射到工作。我在这里做错了什么?

I can't get the above mapping to work. What am I doing wrong here?

推荐答案

这只是简单的不起作用,对不起:(你需要做一个对于很多人来说,只需要一个元素即可获得一个集合。

This just plain does not work, sorry :( You will need to do it as one to many and live with getting a collection with a single element.

如果你真的希望以这种方式工作,你可以通过存储外键ID和在连接表中输入type_name,并告诉它两列都组成了外键。

If you really want it to work this way, you can trick hibernate by storing both the foreign key ID and the type_name in a join table and telling it that both columns make up the foreign key.

这篇关于使用@Where子句进行Hibernate @OneToOne映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆