Avaje - EBean - Partial Object Query disable Lazy Loading

自闭症网瘾萝莉.ら 提交于 2019-12-02 00:45:13

You have 2 alternatives.

Option 1) Use Ebean's built in JSON support that uses Jackson core under the hood. There are a number of writer options available from Ebean's JsonContext.

An example using PathProperties that is applied to both the query and the JSON.

PathProperties pathProperties =
        PathProperties.parse("(id,status,name,shippingAddress(id,line1,city),billingAddress(*),contacts(*))");

List<Customer> customers = Ebean.find(Customer.class)
    .apply(pathProperties)
    .findList();

String jsonString = Ebean.json().toJson(customers, pathProperties);

Option 2) is a newly available feature on version 6.2.2 where you can setDisableLazyLoading(true) on the query.

Reference: https://github.com/ebean-orm/avaje-ebeanorm/issues/360

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!