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.