Avaje - EBean - Partial Object Query disable Lazy Loading

前端 未结 2 944
挽巷
挽巷 2021-01-22 02:50

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 laz

2条回答
  •  后悔当初
    2021-01-22 03:30

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

提交回复
热议问题