Created
April 19, 2015 06:19
-
-
Save thjanssen/7fa350671de484a0127a to your computer and use it in GitHub Desktop.
Result Set Mapping: Constructor Result Mappings (http://www.thoughts-on-java.org/2015/04/result-set-mapping-constructor.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT b.id, b.title, b.version, a.firstName || a.lastName as authorName FROM Book b JOIN Author a ON b.author_id = a.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SqlResultSetMapping( | |
name = "BookValueMapping", | |
classes = @ConstructorResult( | |
targetClass = BookValue.class, | |
columns = { | |
@ColumnResult(name = "id", type = Long.class), | |
@ColumnResult(name = "title"), | |
@ColumnResult(name = "version", type = Long.class), | |
@ColumnResult(name = "authorName")})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<sql-result-set-mapping name="BookValueMappingXml"> | |
<constructor-result target-class="org.thoughts.on.java.jpa.value.BookValue"> | |
<column name="id" class="java.lang.Long"/> | |
<column name="title"/> | |
<column name="version" class="java.lang.Long"/> | |
<column name="authorName"/> | |
</constructor-result> | |
</sql-result-set-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<BookValue> results = this.em.createNativeQuery("SELECT b.id, b.title, b.version, a.firstName || a.lastName as authorName FROM Book b JOIN Author a ON b.author_id = a.id", "BookValueMapping").getResultList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment