JPA默认获取类型 [英] JPA default fetch type

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

问题描述

从我的理解 @OneToOne @ManyToOne JPA批注执行 eager 获取。我希望这些在我的应用程序中被延迟加载,或者至少暗示它(这是hibernate默认的)。我已经开始添加注释 fetch = FetchType.LAZY



eg

  @ManyToOne(可选= false,fetch = FetchType.LAZY)

而不是

pre $ @ManyToOne(可选= false)

这既枯燥又容易出错。有没有办法在应用程序级别执行此操作?在persistence.xml中可能吗?

解决方案

迄今为止,我选择Hibernate遵循JPA规范仅仅是因为我没有收到任何使其可配置的功能请求,这是令人惊讶的TBH。正如你指出的那样,因为Hibernate 3.0使用 hbm.xml 映射文件时默认设置了。



允许通过配置不会违反规范,因为建议了另一个答案。



这么长的故事总之,不,今天是不可能的。如果您希望看到该功能是可配置的,请创建功能请求。


From my understanding @OneToOne and @ManyToOne JPA annotations do an eager fetch. I want these to be lazily loaded in my application, or at least hint at it (which is what hibernate defaults to). I have started to add the annotation fetch = FetchType.LAZY

eg

@ManyToOne(optional = false, fetch = FetchType.LAZY)

instead of

@ManyToOne(optional = false)

This is both tedious and error prone. Is there a way I can do this at an application level? In the persistence.xml perhaps?

解决方案

To date, I have chosen to have Hibernate follow the JPA spec in terms of mapping via annotations simply because I have not received any feature requests for making it configurable, which was surprising TBH. As you point out, since Hibernate 3.0 what you want has been the default set up when using hbm.xml mapping files.

Allowing this via configuration would not violate the spec as another answer suggested.

So long story short, no it is not possible today. Create a feature request if you'd like to see that be configurable.

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

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