[
https://hibernate.onjira.com/browse/HHH-7158?page=com.atlassian.jira.plug...
]
Guenther Demetz edited comment on HHH-7158 at 3/12/12 3:29 AM:
---------------------------------------------------------------
Please substitute *compare(..)* with *isEqual(..)* in method
NaturalIdResolutionCache#areSame,
this should also fix the problem which Eric Dalquist reported on 11 March in
[hibernate-dev] mailing list with subject 'NaturalIdXrefDelegate key comparison
issue'
Following code put at the begin of EntityType#isEqual(Object x, Object y,
SessionFactoryImplementor factory) makes the method stable against null x,y values:
{code:title=EntityType.java|borderStyle=solid}
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
if (x == null || y == null) {
return x == y;
}
...
{code}
was (Author: pb00067):
Please substitute *compare(..)* with *isEqual(..)* in method
NaturalIdResolutionCache#areSame
Following code put at the begin of EntityType#isEqual(Object x, Object y,
SessionFactoryImplementor factory) makes the method stable against null x,y values:
{code:title=EntityType.java|borderStyle=solid}
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
if (x == null || y == null) {
return x == y;
}
...
{code}
Regression: null values on NaturalId's at persist-time are
causing subsequent NPE's and wrong behaviour
-------------------------------------------------------------------------------------------------------
Key: HHH-7158
URL:
https://hibernate.onjira.com/browse/HHH-7158
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.1
Environment: Hibernate 4.1.1, db-indipendent (hsqldb used in testcase)
Reporter: Guenther Demetz
Labels: naturalId
Attachments: TestCasePersistNullNaturalId.jar
Original Estimate: 2h
Remaining Estimate: 2h
Since Hibernate 4.1.1 it is no more possible to have uninitialized NaturalId values when
persisting,
in older versions this was always possible (it was even possible to search NaturalId by
null-values).
The problem stays in the new method
NaturalIdXrefDelegate$NaturalIdResolutionCache#areSame(...)
where org.hibernate.type.Type#compare(...) is used instead of
org.hibernate.type.Type#isEqual(...)
Proposed solution (method NaturalIdResolutionCache#areSame):
if ( !naturalIdTypes[i].isEqual(naturalIdValues[i], values[i], factory)) {
return false;
}
instead of:
if ( naturalIdTypes[i].compare( naturalIdValues[i], values[i] ) != 0 ) {
return false;
}
This makes the first test-case green (see attached Testcase).
The second test-case becomes green, due making method EntityType#isEqual(Object x, Object
y, SessionFactoryImplementor factory)
stable against null x,y values. That sould be trivial.
N.B.: Please consider also that the EntityType#compare(Object x, Object y) implementation
currently always returns 0 (there's a TODO-note),
whilst EntityType#isEqual(Object x, Object y, SessionFactoryImplementor factory)
seems to be a good implementation.
Last but not least: isEqual methods should also be a little bit faster than
compare-method, cause the latter must calculate differences.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira