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.
create pojo objects include necessary attributes , map query fields attributes using
@sqlresultsetmapping
.this approach requires adding lot of additional classes, other seem good.
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.
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.
- ???
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
Post a Comment