org.hibernate.transform.AliasToBeanResultTransformer Java Examples

The following examples show how to use org.hibernate.transform.AliasToBeanResultTransformer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostgreSQLJsonNodeTypeTest.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Test
public void testNativeQueryResultTransformer() {
    doInJPA(entityManager -> {
        List<BookDTO> books = entityManager.createNativeQuery(
            "SELECT " +
            "       b.id as id, " +
            "       b.properties as properties " +
            "FROM book b")
        .unwrap(NativeQuery.class)
        .setResultTransformer(new AliasToBeanResultTransformer(BookDTO.class))
        .getResultList();

        assertEquals(1, books.size());
        BookDTO book = books.get(0);

        assertEquals(expectedPrice(), book.getProperties().get("price").asText());
    });
}
 
Example #2
Source File: MVCCPostgreSQLTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
private PostWithXminAndXmax getPost(EntityManager entityManager, Integer id) {
    List<PostWithXminAndXmax> result = (List<PostWithXminAndXmax>) entityManager.createNativeQuery(
        "SELECT " +
        "    id, title, CAST(xmin AS text), CAST(xmax AS text) " +
        "FROM Post " +
        "WHERE id = :id")
    .setParameter("id", id)
    .unwrap(Query.class)
    .setResultTransformer(new AliasToBeanResultTransformer(PostWithXminAndXmax.class))
    .getResultList();
    return !result.isEmpty() ? result.get(0) : null;
}