-->
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: Using an alias in a formula tag
PostPosted: Wed Apr 28, 2010 12:59 pm 
Newbie

Joined: Thu Mar 04, 2010 10:56 am
Posts: 3
I have a mapping that look something like:

Code:
<hibernate-mapping>
    <class name="User" table="PERSONS">
        <id name="personID" column="PERSON_ID"/>

        <property name="lmsUserName" column="WEB_USERNAME" />

       <property name="userName" insert="false" update="false" unique="true">
            <formula>
           coalesce(lower(WEB_USERNAME), lower(USERNAME))
             </formula>
        </property>

        <join table="APPLICATION_USERS" optional="true">
             <key column="PERSON_ID"/>
             <property name="sasUserName" column="USERNAME"/>
        </join>
    </class>
</hibernate-mapping>


The problem is that when I get an object using this query, the following query is created:

Code:
select
     userimpl0_.PERSON_ID as PERSON1_2_0_,
     userimpl0_.WEB_USERNAME as WEB5_2_0_,
     userimpl0_2_.USERNAME as USERNAME4_0_,
     coalesce(lower(userimpl0_.WEB_USERNAME), lower(userimpl0_.USERNAME)) as formula0_0_,
from PERSONS userimpl0_
left outer join STUDENTS userimpl0_1_
    on userimpl0_.PERSON_ID=userimpl0_1_.PERSON_ID
left outer join APPLICATION_USERS userimpl0_2_
    on userimpl0_.PERSON_ID=userimpl0_2_.PERSON_ID
where userimpl0_.PERSON_ID=?


So both WEB_USERNAME and USERNAME are assumed to be in the PERSONS table which is incorrect (on the line with the coalesce function). I've tried prefixing these columns with the table name, but since hibernate uses alias', we can't reference using the table name any more.

Any ideas on how to reference the alias' that hibernate uses?


Top
 Profile  
 
 Post subject: Re: Using an alias in a formula tag
PostPosted: Wed Apr 28, 2010 2:29 pm 
Newbie

Joined: Thu Mar 04, 2010 10:56 am
Posts: 3
I am definitely not alone. Here are some others:
https://forums.hibernate.org/viewtopic.php?t=992898
http://forum.hibernate.org/viewtopic.php?t=949494
viewtopic.php?t=949306

There should be a way to reference hibernate's aliases. For example, if you prefix a column with the appropriate name, then this table name should be replaced by hibernate's alias for it. Or there should be a way to suppress this prepending from occurring. This should follow some well-defined escape format.


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.