java - JPA Optimizing using custom queries -


i using jpa/hibernate orm , want optimize queries load necessary data specific endpoint. what's best way load subset of attributes of specific class , convert json? endpoints use spring mvc , jackson json mapper.

approaches figured out, haven't tested yet.

  1. create pojo objects include necessary attributes , map query fields attributes using @sqlresultsetmapping.

    this approach requires adding lot of additional classes, other seem good.

  2. ignore overhead in database queries , limit response data jsonviews.

    this can messy real fast, putting different jsonviews seems tedious. queries overhead insignificant curious how map larger more complex queries.

  3. use java.sql.preparedstatements , map resultset manually. additionally use @jsoninclude(include.non_null) use non null values. seems best solution me, ignores jpa entirely , not sure if should go solution. know lose every advantage of orm, seems every other solution needs similar or more complex work.

  4. ???

the last couple of month predominantly developed in javascript/node , liked generate objects needed response. there recommended way of doing such things, me seems common use case.

thanks

we used pojo object these needs before, sometime it's more suitable use 'select new' construction result mapping.

select new com.example.myclass(id, ...) myobject 

maybe can consider that.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -