JPA Native Query (SQL View)

Posted by Uchenna on Stack Overflow See other posts from Stack Overflow or by Uchenna
Published on 2011-11-17T17:47:59Z Indexed on 2011/11/17 17:50 UTC
Read the original article Hit count: 135

Filed under:

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

  1. account and customer tables are created during application startup.
  2. 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

© Stack Overflow or respective owner

Related posts about jpa-2.0