使用 OneToOne 进行休眠

发布于 2024-09-03 21:57:54 字数 436 浏览 3 评论 0原文

我有两个表,

tab1 { col1 (PK), col2, col3 }

tab2 { col1, col2(PK), col3 }

我正在使用 Hibernate 注释使用“OneToOne”进行连接

我有下面的 tab1 Hibernate 类

class tab1 {
   @OneToOne
   @JoinColumn(name = "col2", referencedColumnName = "col1")
   private tab2 t2;
}

我希望运行下面的 sql

select * from tab1 t1, tab2 t2 where t1.col1 = t2.col2

但它没有按我的预期工作。请帮助

I have two tables

tab1 { col1 (PK), col2, col3 }

tab2 { col1, col2(PK), col3 }

I am using Hibernate annotation for joining using "OneToOne"

I have the below Hibernate class for tab1

class tab1 {
   @OneToOne
   @JoinColumn(name = "col2", referencedColumnName = "col1")
   private tab2 t2;
}

i was expecting to run the below sql

select * from tab1 t1, tab2 t2 where t1.col1 = t2.col2

But it is not working as i expected.Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-09-10 21:57:55

如果您想要检索 tab1 实体并使用单个选择预先加载关联的 tab2,请使用“fetch”联接:

SELECT t1 from Tab1 t1 left join fetch t1.t2

您需要考虑关联并通过关联进行导航使用 ORM 时。

If you want to retrieve tab1 entities and to eager load the associated tab2 using a single select, use a "fetch" join:

SELECT t1 from Tab1 t1 left join fetch t1.t2

You need to think associations and to navigate through associations when working with an ORM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文