JPA Native Query (SQL View)
- by Uchenna
I have two Entities Customer and Account.
@Entity
@Table(name="customer")
public class Customer
{
private Long id;
private String name;
private String accountType;
private String accountName;
...
}
@Entity
@Table(name="account")
public class Account
{
private Long id;
private String accountName;
private String accountType;
...
}
i have a an sql query
select a.id as account_id, a.account_name, a.account_type, d.id, d.name
from account a, customer d
Assumption
account and customer tables are created during application startup.
accountType and accountName fields of Customer entity should not be created. That is,
only id and name columns will be created.
Question
How do i run the above sql query and return a Customer Entity Object with the accountType and accountName properties populated with sql query's account_name and account_type values.
Thanks