I have a situation where I have a single native query which contains data of 2 entity classes, how can I map that data to the entity classes by @SqlResultSetMapping? For Example
Native query:- select customer.name, address.area from customer, address where customer.id=address.custid;
2 Entity Classes like customer and address with name as a variable in customer and area as a variable in the address entity class.
Customer class:
@Entity
public class Customer {
@Id
private String name;
getters and setters
.....
.....
.....
}
Address Class entity:
@Entity
public class Address{
@Id
private String area;
getters and setters
.....
.....
.....
}
To map the native query with the entity class it can be done by giving @SqlResultSetMapping in entity and give the name of the mapping in the nativeQuery
Query query = entityManager.createNativeQuery(sbQuery, "checkInfoMapping");
it will check the mapping name and map to the respective entity class, this can be done for a single entity class.
Can it be done if I have data from the native query of 2 entity classes, if yes how can I map it to the entity class with native query?