I have a Hibernate persisted class 'MyClass' with three properties.
When trying to lookup an instance with a specific 'id' using a HQL query, I run into trouble.
When using a property named 'id' in HQL, it is interpreted as a shortcut for whatever property Hibernate uses for primary key. In the documentation (11.7) I read: "The special property (lowercase) id may be used to reference the unique identifier of an object." In my case this behaviour effectively hides the "real" property 'id'.
How can I rewrite my HQL query so that it uses my property 'id'?
Best regards /Rickard
PS. A workaround would be to provide my own SQL query, but I would like to solve this problem without leaving HQL. [ September 01, 2004: Message edited by: Rickard Johansson ]
What I have a problem with is that Hibernate puts a restriction (although I admit that it is a rather small restriction) on how the properties of my business objects are named.
When building a new system, knowing from the start that Hibernate is being used, it is not a big deal to avoid using business meaning properties with the name 'id'. But in situations when migrating an existing system to Hibernate, or in when the business objects are modelled before the ORM implementation is chosen, you want to avoid unnecessary changes to the business objects.
Why not make it a configuration property? If not stated, use 'id' as default alias, or state another name (or turn of the alias feature, which is what I would prefer).
When incorporating third party frameworks in systems with estimated long lifespan I try to do everything possible to avoid having to maintain a patched version of any third party framework. This means that I prefer getting invlolved in the development of an open source project (making the change a part of the official release) over maintaining a private patch.