Avaje - EBean - 部分对象查询禁用延迟加载 [英] Avaje - EBean - Partial Object Query disable Lazy Loading

查看:19
本文介绍了Avaje - EBean - 部分对象查询禁用延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Play 开发应用!框架 2.1.3,将 EBean 用于模型层我希望能够执行部分对象查询,并且当我序列化为 JSON 以准备将结果发送回用户时,不会按需延迟加载未选择的属性.

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.

我尝试将 AutoFetch 设置为 false,我也尝试在序列化为 JSON 之前结束事务(我最终得到一个 Transaction is Inactive 错误)我还添加了注释 @Lazy(false) 在我的模型类上.

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.

同样,我也有一个一对多关联,我想查询它的前 3 行,我使用了 new FetchConfig().queryFirst(2) 但我猜测由于相同的延迟加载问题,我最终得到了整个相关的关联行.

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.

看手册,我读了这个(EBean Partial Objects):

Looking at the manual, I read this (EBean Partial Objects):

Partial Object 会根据需要延迟加载其余数据您获取或设置它没有的属性.

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!

推荐答案

我通过使用标准的 JDBC 接口解决了这个问题,使用 StatementsResultSets 在查询我不需要延迟加载.

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.

顺便说一句,在 Scala 的情况下,直接字段访问不使用延迟加载,但不幸的是,它不是我用于我的应用程序的语言.

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屋!

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