08 März 2013

JpaSqlResultMapper instead of Constructor Expression

The previously mentioned JpaSqlResultMapper can also used as a replacement of the JPA Constructor Expression.

Query q = em.createQuery("SELECT c.id, c.type, c.euroExchangeRate FROM Closing c");
List<ClosingRecord> list = JpaSqlResultMapper.list(q, ClosingRecord.class);
The advantage of this approach is, that you don't have to worry when you are moving ClosingRecord to another package because the full qualified class name is not mentioned in the JPQL query.
So it's more refactoring friendly.

Keine Kommentare: