-
-
Save Mukundhan-I2I/595a2e7042a6d93eea3b549da36d3fcd to your computer and use it in GitHub Desktop.
usage example of org.hibernate.Transformers.aliasToBean
This file contains 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
public class CustomerDTO { | |
private String firstName, lastName; | |
// getter & setters | |
} |
This file contains 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
import org.hibernate.SQLQuery; | |
import org.hibernate.Session; | |
import org.hibernate.transform.Transformers; | |
... | |
SQLQuery query = session.createSQLQuery("SELECT FNAME as firstName, LNAME as lastName FROM CUSTOMER"); | |
query.setResultTransformer(Transformers.aliasToBean(CustomerDTO.class)); | |
query.addScalar("firstName").addScalar("lastName"); | |
List<CustomerDTO> list = query.list(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment