Hibernate 中一对一、多对一和一对多的默认获取类型 [英] Default fetch type for one-to-one, many-to-one and one-to-many in Hibernate

查看:28
本文介绍了Hibernate 中一对一、多对一和一对多的默认获取类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

休眠映射中的默认获取类型是什么?

What is the default fetch type in hibernate mappings?

探索之后我了解到的是:

What I got to know after exploring is:

  • 一对一是渴望.
  • 对于一对多来说,它懒惰.

但在 Eclipse 中对其进行测试后,它非常渴望.

But after testing it in Eclipse, it was eager for all.

这取决于我使用的是 JPA 还是 Hibernate?

Does it depend on whether I am using JPA or Hibernate?

推荐答案

这取决于你使用的是 JPA 还是 Hibernate.

It depends on whether you are using JPA or Hibernate.

JPA 2.0 规范,默认值是:

OneToMany: LAZY
ManyToOne: EAGER
ManyToMany: LAZY
OneToOne: EAGER

在休眠状态下,一切都是懒惰的

And in hibernate, all is Lazy

更新:

最新版本的 Hibernate 与上述 JPA 默认值一致.

The latest version of Hibernate aligns with the above JPA defaults.

这篇关于Hibernate 中一对一、多对一和一对多的默认获取类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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