[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3895) accessing proxy will not unwrap / initialize entity if the accessed property is the primary-key / id of the entity
Diego Plentz (JIRA)
noreply at atlassian.com
Tue May 5 14:01:18 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3895?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33091#action_33091 ]
Diego Plentz commented on HHH-3895:
-----------------------------------
This could be a BIG problem when you use the ID of the class in a equals method, like this:
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof MyEntity))
return false;
final MyEntity other = (MyEntity) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.getId())) <--- wrong behavior, because other.getId() returns null
return false;
return true;
}
To solve the problem, you must access the property directly (other.id).
I think this happens only with JavaAssist(but I can be wrong). Steve, Emmanuel, any thoughts?
> accessing proxy will not unwrap / initialize entity if the accessed property is the primary-key / id of the entity
> ------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-3895
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3895
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.3.1
> Environment: Envers 3.5 with Hibernate Core, -annotations, -common-annotations 3.5 and Spring
> Reporter: Alexander Fröhlich
>
> An audited entity - which is a property of the audited entity I fetch from db - will return null if I call getPk() / getID() on it, where pk / id is the primary key of the entity.
> mainEntity = auditReader.createQuery()for.....getSingleResult();
> mainEntity.getPk(); // returns pk - fine
> mainEntity.getPropertyEntity().getPk(); // returns null IF no other properties of 'propertyEntity' have been accessed before
> mainEntity.getPropertyEntity().getAnyOtherProperty(); // all fine
>
> see forum for more details:
> http://www.jboss.org/index.html?module=bb&op=viewtopic&t=154798
--
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list