Hibernate Native SQL
vembubalaji
16.8K views
01 Hibernate Native SQL
Hibernate Native SQL - Introduction Use parameter binding in native SQL queries Adding scalars Native Joins Adding joins with entity mapping Basic Result set mapping using @SqlResultSetMapping Mapping Non-managed entities via result transformer Mapping Non-managed entities via result Custom Transformer
Adding joins with entity mapping.
- We can also use addEntity() and addJoin() methods to fetch the data from associated table using tables join. The above query can be re-written as following;
A quick sample. Check out the JAVA class and SQL file
1
2
3
4
5
6
7
8
9
10
// { autofold
package com.tu.nativesqlsample;
import java.util.List;
import java.util.logging.Logger;
import org.hibernate.Session;
import com.tu.hibernate.HibernateUtil;
import com.tu.hibernate.entity.Team;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- Notice the second query, which fetches the Domain details. This is the eager Loading of the requested object
- [aliasname].* is used to return all properties of an entity. When we use addEntity() and addJoin() with join queries like above it returns both the objects, as shown above.
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
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