Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

execute native query that returns entity + another columns

890830Sep 27 2011 — edited Oct 4 2011
Hi all;
I have a native sql where I select all entity(Customer) info + 2 String codes that I need to display: SELECT Customer.*, professionCode CODEPROF, educationCode CODEEDU FROM ... very complicated stuff
The query can not be written in JPQL because I need to use subquery in FROM clause and as I know, it's impossible.

So I created new object CustomerRow that extend my entity Customer

@SqlResultSetMapping(name="custProfEdu",
entities={
@EntityResult(entityClass=data.jpa.entity.Customer.class)},
columns={
@ColumnResult(name="CODEPROF"),
@ColumnResult(name="CODEEDU")}
)
public class CustomerRow extends Customer {
private String profCode;
private String eduCode;
...
+ getters and setters
...
}

Into my manager class I added following row : natQuery = em.createNativeQuery(sql, "custProfEdu");
After executing I get the message: There is no query result mapping for "null" with name "custProfEdu".

Can anybody tell me, what am I doing wrong? Is it good idea just to extend the entity with two necessary Strings and use SqlResultSetMapping?

Thanks a lot
Mar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 1 2011
Added on Sep 27 2011
3 comments
1,077 views