Hacker News new | ask | show | jobs
by bni 4065 days ago
From the article:

"So our strategy has been to reduce the number of relations between entities to what is strictly necessary, and occasionally to use JPA DTOs when a subset of data is needed for a rather complex entity. Such DTOs are populated using the constructor selector syntax in JPQL queries and JPA is generally smart enough to generate far more optimal queries then."

I have been using this "pattern" a lot lately, its great. looks something like this:

SELECT NEW mypackage.Pojo( e.id, oe.name ) FROM MyEntity e JOIN e.otherEntity oe WHERE e.someProperty = :parameter1

Its also possible to place these in external files, working around Javas inability to have multi line strings after all these years.