[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7177) NullPointerException after persisting null NaturalId-values in combination with @NaturalIdCache
Guenther Demetz (JIRA)
noreply at atlassian.com
Thu May 3 02:59:48 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46485#comment-46485 ]
Guenther Demetz commented on HHH-7177:
--------------------------------------
This issue can be closed as it's fixed in 4.1.3 through other commits, because now the testcase passes
> NullPointerException after persisting null NaturalId-values in combination with @NaturalIdCache
> -----------------------------------------------------------------------------------------------
>
> Key: HHH-7177
> URL: https://hibernate.onjira.com/browse/HHH-7177
> Project: Hibernate ORM
> Issue Type: Bug
> Components: caching (L2)
> Affects Versions: 4.1.1
> Reporter: Guenther Demetz
> Priority: Minor
> Labels: 2L-Cache, naturalId
> Attachments: TestCaseHHH-7177.jar
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> Since Steve has fixed HHH-7158 (see org.hibernate.test.naturalid.nullable.NullableNaturalIdTest),
> there's no NullPointerException anymore when persisting null values.
> But a NullPointerException raises again when annotating the entity class with @NaturalIdCache.
> Cause:
> {code:title=NaturalIdCacheKey.java constructor|borderStyle=solid}
> result = prime * result + type.getHashCode( value, factory ); // raises NPE when value is null
> {code}
> Proposed fix:
> {code:title=NaturalIdCacheKey.java constructor|borderStyle=solid}
> result = prime * result + (value == null ? 0 : type.getHashCode( value, factory ));
> {code}
> Testcase (see attachement):
> {code:title=org.hibernate.test.annotations.naturalid.NaturalIdOnSingleManyToOneTest.java|borderStyle=solid}
> @Test
> public void testManyToOnePersistMutableNaturalIdWithNullValue() {
> NaturalIdOnManyToOne singleManyToOne = new NaturalIdOnManyToOne();
> Citizen c1 = new Citizen();
> c1.setFirstname( "Emmanuel" );
> c1.setLastname( "Bernard" );
> c1.setSsn( "1234" );
> State france = new State();
> france.setName( "Ile de France" );
> c1.setState( null );
> singleManyToOne.setCitizen( c1 );
> Session s = openSession();
> Transaction tx = s.beginTransaction();
> s.persist( france );
> s.persist( c1 );
> s.persist( singleManyToOne );
>
> c1.setState( france );
> s.flush(); // --> java.lang.NullPointerException below raises, test passes when removing @NaturalIdCache annotation on Citizen entity
> {code}
--
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