[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7158) Regression: null values on NaturalId's at persist-time are causing subsequent NPE's and wrong behaviour
Guenther Demetz (JIRA)
noreply at atlassian.com
Thu Mar 8 09:24:49 EST 2012
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
Attachments: TestCasePersistNullNaturalId.jar
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
More information about the hibernate-issues
mailing list