-->
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.  [ 2 posts ] 
Author Message
 Post subject: Native query using orm.xml
PostPosted: Wed Jul 29, 2009 4:10 pm 
Beginner
Beginner

Joined: Fri Sep 12, 2008 10:55 am
Posts: 33
I have a named-native-query entry for a special case query that I need to use. The problem arises when I have two tables that have the same column names.
Quote:
Table A:
A_ID
CAP
..
Table B:
B_ID
CAP
..


I wanted to put this query in an orm.xml instead of hard coding all this:
Code:
String query = "SELECT {a.*}, {b.*} ...";

Session hibernateSession = (Session) entityManager.getDelegate();

SQLQuery sqlQuery =
    hibernateSession.createSQLQuery( query ).addEntity("a", A.class).addEntity("b", B.class);


With the "hibernate" way, I have the put the braces around so that it's smart enough to know what to map to where. However, if I attempted to put this in an orm.xml up front, and then simply create the sql-result-set-mapping and entity-result, I have no way to tell it which alias' map to which class.

So what ends up happening is, whatever value A.capacity has, ends up in B.capacity entity also. Because hibernate is going by the name, nothing else. It isn't applying alias' at all. The query for A.CAP comes first, so when it is trying to create the B class, it's just finding the first "CAP" in the result set and setting that value.

So, ultimately what I'm saying is, with orm.xml, is there no way to define what alias goes with what entity-result?


Top
 Profile  
 
 Post subject: Re: Native query using orm.xml
PostPosted: Fri Aug 21, 2009 12:19 pm 
Beginner
Beginner

Joined: Fri Sep 12, 2008 10:55 am
Posts: 33
Does anyone have anything?


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

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.