[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1851?page=all ]
Steve Ebersole updated HHH-1851:
--------------------------------
Summary: relax special handling of 'id' property (was:
"special" identifier property in HQL unnecessaryily causing problems)
Description:
Hibernate has long treated 'id' in a special manner in HQL and Criteria queries.
The drawback to this has always been that it effectively means users cannot define
non-identifier properties named id and refer to those properties in HQL/Criteria queries.
Thus, I will change this such that:
(1) 'id' can still be used to refer to the identifier property, whatever the
property's actual name, as long as the entity does not define a non-identitifer
property named id.
(2) if the entity defines a non-identifier property named 'id', using 'id'
in HQL or Criteria queries will refer to this non-identifier property; users would need to
refer to the identifier property by its actual name.
FYI, the original reason for this feature was to support entity's which did not define
an identifier property at all (users were responsible for managing the ids seperately.
That feature was never really recommended and has been deprecated since early in the 3.x
development.
was:
I HAVE REPORTED THIS PROBLEM BEFORE IN HHH-1127. THEN IT WAS FLAGGED AS
"DUPLICATE" AND CLOSED PLEASE TELL ME WHAT IS THE ID OF THE REPORT WHICH THIS
SUPPOSEDLY DUPLICATES?
When a user decides to use the name "id" as the name of a property, HQL queries
break with unspecific exceptions, because HQL assumes "id" as reserved for the
Hibernate id attribute defined in the hbm file using the <id .../> tag. This is bad
design in our view, because it puts an unnecessary constraint and interference with the
otherwise transparent "object persistence for idiomatic Java."
For example, a mapping file may contain:
<class name="MyObject">
<id name="internalId" ... />
<property name="id" .../>
<property name="foo" .../>
</class>
And since even the <id .../> element has a @name property, why can't HQL use
that name rather than shadowing a perfectly good identifier for a normal property?
The HQL query
from MyObject where id='123'
and this would fail because 'id' in HQL means the 'internalId' property
not the property called 'id'. But if I wanted to access the internalId I could
just as well have sayd:
from MyObject where internalId='123'
I do not understand the value of this feature and it is causing us tremendous problems,
because our object property names are fixed by some larger standards body and I can't
just replace "id" with some other name just because of HQL!
I am currently hacking every version of Hibernate by changing only one line in
org.hibernate.persister.entity.EntityPersister
from
public static final String ENTITY_ID = "id";
to
public static final String ENTITY_ID = "hid";
But that of course is a problem and also breaking it for anyone who uses "hid"
as a normal property name.
I really don't understand what the value of this feature is and I am asking you to
drop it alltogether or turn it into some really weird name or some function, whatever, but
this "special" id attribute really, really hurts.
Please, if you close this issue again, at least comment about your rationale or link it
with the bug where it had been discussed. Thank you!
relax special handling of 'id' property
---------------------------------------
Key: HHH-1851
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1851
Project: Hibernate3
Type: Improvement
Components: query-hql
Environment: independent, all versions all databases.
Reporter: Gunther Schadow
Assignee: Steve Ebersole
Fix For: 3.2.2
Original Estimate: 1 hour
Remaining: 1 hour
Hibernate has long treated 'id' in a special manner in HQL and Criteria queries.
The drawback to this has always been that it effectively means users cannot define
non-identifier properties named id and refer to those properties in HQL/Criteria queries.
Thus, I will change this such that:
(1) 'id' can still be used to refer to the identifier property, whatever the
property's actual name, as long as the entity does not define a non-identitifer
property named id.
(2) if the entity defines a non-identifier property named 'id', using
'id' in HQL or Criteria queries will refer to this non-identifier property; users
would need to refer to the identifier property by its actual name.
FYI, the original reason for this feature was to support entity's which did not
define an identifier property at all (users were responsible for managing the ids
seperately. That feature was never really recommended and has been deprecated since early
in the 3.x development.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira