-->
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.  [ 3 posts ] 
Author Message
 Post subject: Referencing an "id" property in HQL
PostPosted: Mon Mar 01, 2004 2:55 pm 
Newbie

Joined: Mon Feb 23, 2004 2:45 pm
Posts: 6
I have seen a thread about id being a keword in HQL, couldn't find it though...

Code:
<hibernate-mapping>
<class name="User" table="STAFF">
<id name="sid" column="sid"  type="int" unsaved-value="0">
<generator class="sequence">
<param name="sequence">staff_seq</param>
</generator>
</id>
       
<property name="id"/>
<property name="password"/>   
<property name="firstName"/>
...


I have a property sid, which is the Primary Key for the class and another property called id.

Hibernate generates the following SQL:

Code:
select ... from STAFF user0_ where (user0_.sid=? )


when executing:

Code:
q = session.createQuery("from User as u where u.id = :name");
q.setString("name", id.toUpperCase());


Is u.id referencing to the User object id property (my expectation) or the id column (sid property) as specified in the mapping document .

Does that mean that I can't reference a property named id when HQL-ing?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 10:38 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
Yes, id is a keyword in HQL. u.id is referencing your sid, because you mapped it with the id XML tag.

Quote:
Does that mean that I can't reference a property named id when HQL-ing?


No, try something like this... <property name="someOtherID" column="id"/>
someOtherID -> Java Field
id -> DB column

Check out this section in the docs... http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-7

Hope this helped. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 9:58 am 
Newbie

Joined: Mon Feb 23, 2004 2:45 pm
Posts: 6
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.