简体   繁体   English

获取持久实体时不获取byte []列的最佳方法是什么?

[英]What is the best way to NOT fetch a byte[] column when getting a persistent entity?

The table has multiple properties which we want to always be fetched. 该表具有多个我们希望始终获取的属性。 But it also has one property which is very large. 但是它也有一个非常大的属性。 When getting the information to display a list of items to the user the request will be significantly slower if the large property is fetched and it's not even used. 当获取信息以向用户显示项目列表时,如果获取了大属性并且甚至没有使用它,则请求的速度将大大降低。

So far I've only managed to make it work by wrapping that byte[] in a separate Object and referencing it with a @ManyToOne(fetch = FetchType.LAZY) which seems like poor design. 到目前为止,我仅设法通过将byte []包装在单独的Object中并使用@ManyToOne(fetch = FetchType.LAZY)对其进行引用来使其工作,这似乎是糟糕的设计。 @Lob @Basic and @OneToOne don't seem to work and I would rather not have that property in a separate Object anyway. @Lob @Basic和@OneToOne似乎不起作用,无论如何我还是不想在单独的Object中拥有该属性。

It sounds like you have tried annotating the byte[] array with @Basic(fetch = FetchType.LAZY) . 听起来您尝试使用@Basic(fetch = FetchType.LAZY)注释byte []数组。 When using the @Basic annotation and lazy fetching additional hibernate options must be set. 使用@Basic批注和延迟获取时,必须设置其他休眠选项。 See the Hibernate Documentation - Performing Enhancement Section 请参见Hibernate文档- 执行增强部分

Specifically, the hibernate.enhancer.enableLazyInitialization property must be set to true. 具体来说,必须将hibernate.enhancer.enableLazyInitialization属性设置为true。 By default it is not enabled. 默认情况下未启用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM