-->
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: Special meaning of 'id' when naming properties?
PostPosted: Mon Mar 14, 2005 5:00 pm 
Newbie

Joined: Mon Mar 14, 2005 4:05 pm
Posts: 1
Hi,

I have a quick question regarding the naming of properties for hibernatable objects. Does the property 'id' have a special meaning? I'll post as little as neccessary, but I can give more details upon request. I tried this with Hibernate that comes bundled with jboss 3.2.6 and 4.0.1sp1 with the same results. I have a minimal object called Bernd with only two properties:

notTheId : This is the mapped, auto-generated primary key with an arbitrary property name that ends in 'id'. 'packageId', 'someOtherId' or anything alike does the trick.

id : This is just a property field with the name 'id'.

I try to query an instance of this object (both a Criteria query and a session.find(...) query give the same result):

Code:
List test = session.find("from Bernd as b where b.id='asking for id' and b.notTheId='asking for notTheId'");


Looking in the DEBUG log when this statement is called reveals, that somehow the property I query for gets changed from searching in id into whatever name the primary key field is, if it ends in ...Id as well:

Code:
15:07:56,579 DEBUG [JTATransaction] Looking for UserTransaction under: UserTransaction
15:07:56,580 DEBUG [JTATransaction] Obtained UserTransaction
15:07:56,580 DEBUG [JTATransaction] beginning new transaction
15:07:56,580 DEBUG [SessionImpl] find: from Bernd as b where b.id='asking for id' and b.notTheId='asking for notTheId'
15:07:56,581 DEBUG [QueryTranslator] compiling query
15:07:56,582 DEBUG [SessionImpl] flushing session
15:07:56,582 DEBUG [SessionImpl] Flushing entities and processing referenced collections
15:07:56,582 DEBUG [SessionImpl] Processing unreferenced collections
15:07:56,582 DEBUG [SessionImpl] Scheduling collection removes/(re)creates/updates
15:07:56,583 DEBUG [SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
15:07:56,583 DEBUG [SessionImpl] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
15:07:56,583 DEBUG [SessionImpl] Dont need to execute flush
15:07:56,583 DEBUG [QueryTranslator] HQL: from com.getwellnetwork.workflow.jdo.Bernd as b where b.id='asking for id' and b.notTheId='asking for notTheId'
15:07:56,583 DEBUG [QueryTranslator] SQL: select bernd0_.notTheId as notTheId, bernd0_.id as id from Bernd bernd0_ where (bernd0_.notTheId='asking for id' )and(bernd0_.notTheId='asking for notTheId' )
15:07:56,584 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
15:07:56,585 DEBUG [SQL] select bernd0_.notTheId as notTheId, bernd0_.id as id from Bernd bernd0_ where (bernd0_.notTheId='asking for id')and(bernd0_.notTheId='asking for notTheId' )
15:07:56,585 INFO  [STDOUT] Hibernate: select bernd0_.notTheId as notTheId, bernd0_.id as id from Bernd bernd0_ where (bernd0_.notTheId='asking for id' )and(bernd0_.notTheId='asking for notTheId' )
15:07:56,585 DEBUG [BatcherImpl] preparing statement
15:07:56,586 DEBUG [Loader] processing result set
15:07:56,586 DEBUG [Loader] done processing result set (0 rows)


Note the two lines in there. First, Hibernate has it right:
15:07:56,580 DEBUG [SessionImpl] find: from Bernd as b where b.id='asking for id' and b.notTheId='asking for notTheId'

When it translates the query, it seems to have changed it:
15:07:56,583 DEBUG [QueryTranslator] SQL: select bernd0_.notTheId as notTheId, bernd0_.id as id from Bernd bernd0_ where (bernd0_.notTheId='asking for id' )and(bernd0_.notTheId='asking for notTheId' )

Any hint in the right direction would be greatly appreciated.

Regards,
Bernd.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 1:53 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
Yes, HQL overrides your mapping file with it's own idea what a property named "id" is supposed to be. If you need your property "id" in HQL queries, you need to rename it. You could presumably alias it or something. But it's a big pain in the butt for no benefits.

The special property 'id' in HQL is a great annoyance to me, a showstopper, becasue I can't just decide not to use the name "id" for a normal property. My API/Object Model is from a standard and needs to use the standard names.

I have filed a bug report at http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1127 with a patch that "fixes" the problem for me. But that was simply closed without further comment, marked as "duplicate" without a link to the bug or discussion that it supposedly duplicates.

I think this is bad design of HQL and should somehow be repealed. It's an entirely unnecessary "feature" because all id properties have a normal name defined in the mapping file. If they wanted a "feature" they shouldn't just use up a normal looking property name, instead they should have used some special tag, such as x.@id or x.hibernateId or something less likely to conflict.


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.