-
1. Re: Using EntityQuery: best practices
lvdberg Oct 12, 2010 12:31 PM (in response to kwutzke)Hi,
especially for these cases Hibernate has the new SomethingClass available. You create a view class with the default constructor and a constructor which matches the vars you want to use.
The query must be changed to
SELECT new playerStat(pl.lastName, pl.firstName, ps.jerseyNbr, ps.isStarter, ps.pf, SUM(st.pts), (SUM(st.pts)-SUM(st.ftm)-SUM(st.tpm)*3)/2, SUM(st.tpm), SUM(st.ftm), SUM(st.fta)) from ...
Instead of an object array you will geta a list with the newly created PlayerStat objects. Your code is much cleaner and you save yourself some additional transfer work.
Leo
-
2. Re: Using EntityQuery: best practices
kwutzke Oct 12, 2010 2:02 PM (in response to kwutzke)Thanks for your answer. I very much appreciate your extremely valuable tips.
BTW the syntax isn't specific to Hibernate, it's JPA-compatible.
I just found this in my JPA book:
Constructor expressions are powerful tools for constructing coarse-grained data transfer objects or view objects for use in other application tiers.
This is interesting! I didn't know fine-grained entity objects are considered model domain, whereas coarse-grained non-entity objects are considered rather view domain. That really changes my view on coarse-grained objects.
Karsten