-->
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: How to define alias of super type with {alias.*} syntax
PostPosted: Mon Jun 20, 2016 9:39 am 
Newbie

Joined: Mon Jun 20, 2016 9:17 am
Posts: 1
I have the following query using createSQLQuery.
A and B are both inheriting from a common super class and I would like to select A and B with the addEntity method.
I therefore need to select A and B with the {alias.*} syntax as I get column clashes otherwise.

Code:
SQLQuery query = Database.getHibernateSessionProvider().getSession().createSQLQuery(""
        + "select {a.*}, {b.*} from A a "
        + " inner join SUPER a_super ON a_super.id = a.id "
        + " inner join SUPER b_super ON b_super.id = b.id "
        + " inner join A a ON a.key = b.key ");
query.addEntity("a", A.class). addEntity("b", B.class).list();


My question is how I can influence the alias of the super type (a_super and b_super)? It seems that Hibernate is expanding {a.*} to a.xxx for field in the sub type and a_1_.xxx in the super type. This means in order to get my query working I need to hardcode those aliases which is not the desired solution as I don't know if this is stable or not.

Code:
SQLQuery query = Database.getHibernateSessionProvider().getSession().createSQLQuery(""
        + "select {a.*}, {b.*} from A a "
        + " inner join SUPER a_1_ ON a_1_.id = a.id "
        + " inner join SUPER b_1_ ON b_1_.id = b.id "
        + " inner join A a ON a.key = b.key ");
query.addEntity("a", A.class). addEntity("b", B.class).list();


Can anyone help with this? Is there a way to define the alias of the super type myself?


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.