Avaje-EBean-部分对象查询禁用延迟加载 [英] Avaje - EBean - Partial Object Query disable Lazy Loading
问题描述
我正在使用Play开发一个应用!框架2.1.3,使用EBean作为模型层,我希望能够执行部分对象查询,并且当我序列化为JSON以将结果发送回用户时,不需要按需延迟加载未选择的属性. /p>
我尝试将AutoFetch设置为false,我还尝试在序列化为JSON之前结束事务(最终导致Transaction is Inactive错误),我还在模型类上添加了注释@Lazy(false)
. /p>
在同一注上,我也有一个一对多关联,我想查询它的前三行,我使用了new FetchConfig().queryFirst(2)
,但是我想由于同样的延迟加载问题,我最终得到了整个相关的关联行.
我在阅读手册时读到了这本书( EBean Partial Objects ):
在以下情况下,部分对象将按需延迟加载其余数据: 您获得或设置了它没有的属性.
有没有解决的办法,我尝试过的一切似乎都不起作用!
我通过在不需要懒加载的查询上使用标准的JDBC接口(Statements
和ResultSets
)解决了此问题. /p>
请注意,在Scala中,直接字段访问不使用延迟加载,但是不幸的是,这不是我在应用程序中使用的语言.
I'm developing an app using Play! Framework 2.1.3, using EBean for the model layer I wanna be able to execute a Partial Object Query and not have the un-selected properties lazy loaded on demand when I serialize to JSON in preparation to send the result back to the user.
I have tried setting AutoFetch to false, I have also tried to end the transaction before serializing to JSON (I ended up getting a Transaction is Inactive error) I've also added the annotation @Lazy(false)
on my model class.
On the same note, I also have a One-to-Many association, and I wanna Query the first 3 rows of it, I used new FetchConfig().queryFirst(2)
but I guess due to the same lazy loading issue, I end up getting the whole related association rows.
Looking at the manual, I read this (EBean Partial Objects):
A Partial Object will lazy load the rest of the data on demand when you get or set a property it does not have.
Is there a way around this, nothing I tried seemed to work!
I have solved this issue by using the standard JDBC interface using Statements
and ResultSets
on the queries that I require not to have lazy loading on.
As a side note, turns out that in the case of Scala, direct field access does not use Lazy Loading, but unfortunately it is not the language I am using for my application.
这篇关于Avaje-EBean-部分对象查询禁用延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!