These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: execute native query that returns entity + another columns
PostPosted: Tue Sep 27, 2011 10:55 am 
Newbie

Joined: Tue Sep 27, 2011 10:48 am
Posts: 1
Hi all;
I have a native sql where I select all entity(Customer) info + 2 String codes that I need to display:
Code:
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

Code:
@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 :
Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.