Back
Close

Hibernate Native SQL

vembubalaji
13.6K views

Mapping Non-managed entities via result transformer

  • Until now, we have been mapping result sets to specific entities, what if we want to map the result set directly onto a JavaBean rather than an entity. For this, we can us the Result transformer
  • Here again, we have implicit transformer, explicit transformers.
  • For Implicit transformation, we would use the Transformers.aliasToBean method. Here the understanding is that the columns returned from the result set have the same naming convention with that of the mapped JavaBean. In this case, the CustomDTO’s attributes.
  • In case the columns returned from the result set names does not match the names on the mapped JavaBean attributes, and then we opt for the explicit transformation.
A quick sample. Check out the JAVA class and SQL file
// { autofold
package com.tu.nativesqlsample;
import java.util.List;
import java.util.logging.Logger;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants