[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-7160) NaturalIdXrefDelegate#cache() needs to remove obsolete entries in shared cache when NaturalId values changed
Guenther Demetz (JIRA)
noreply at atlassian.com
Fri Mar 16 13:06:48 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-7160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45985#comment-45985 ]
Guenther Demetz edited comment on HHH-7160 at 3/16/12 12:06 PM:
----------------------------------------------------------------
The according test-method to add in org.hibernate.test.annotations.naturalid.NaturalIdOnSingleManyToOneTest
{code:title=org.hibernate.test.annotations.naturalid.NaturalIdOnSingleManyToOneTest.java|borderStyle=solid}
@Test
@TestForIssue( jiraKey = "HHH-7160" )
public void testHHH7160() {
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" );
State italy = new State();
italy.setName( "Italia" );
c1.setState( france );
singleManyToOne.setCitizen( c1 );
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist( france );
s.persist( italy );
s.persist( c1 );
s.persist( singleManyToOne );
c1.setState( italy );
s.flush(); // due fix HHH-7160, now the obsolete entry should get evicted from shared cache
assertNull(s.byNaturalId(Citizen.class).using("state", france).using("ssn","1234" ).load());
}
{code}
N.B.: To make the testcase work, the NaturalId on state in Citizen has to be turned into a mutable one:
{code:title=org.hibernate.test.annotations.naturalid.Citizen .java|borderStyle=solid}
@NaturalId(mutable=true)
@ManyToOne
private State state;
{code}
was (Author: pb00067):
The according test-method to add in org.hibernate.test.annotations.naturalid.NaturalIdOnSingleManyToOneTest
{code:title=org.hibernate.test.annotations.naturalid.NaturalIdOnSingleManyToOneTest.java|borderStyle=solid}
@Test
@TestForIssue( jiraKey = "HHH-7160" )
public void testHHH7160() {
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" );
State italy = new State();
italy.setName( "Italia" );
c1.setState( france );
singleManyToOne.setCitizen( c1 );
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist( france );
s.persist( italy );
s.persist( c1 );
s.persist( singleManyToOne );
c1.setState( italy );
s.flush(); // due fix HHH-7160, now the obsolete entry should get evicted from shared cache
assertNull(s.byNaturalId(Citizen.class).using("state", france).using("ssn","1234" ).load());
}
{code}
> NaturalIdXrefDelegate#cache() needs to remove obsolete entries in shared cache when NaturalId values changed
> ------------------------------------------------------------------------------------------------------------
>
> Key: HHH-7160
> URL: https://hibernate.onjira.com/browse/HHH-7160
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Affects Versions: 4.1.1
> Environment: Hibernate4.1.1
> Reporter: Guenther Demetz
> Assignee: Steve Ebersole
> Labels: naturalId
> Fix For: 4.1.2
>
> Attachments: TestCaseNaturalIdChangeBetweenPersistAndFlush.jar
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> Method NaturalIdXrefDelegate#cache() misses to remove obsolete entry in naturalIdToPkMap when NaturalId values changed,
> thus NaturalIdAccess delivers results even by searching with obsolete values (see attached Testcase).
> Cause:
> following instruction is missing in Method NaturalIdXrefDelegate#cache():
> if ( initial != null ) {
> if ( areSame( naturalIdValues, initial.getValues()) ) {
> return false;
> }
> naturalIdToPkMap.remove(initial); // <-- this instruciton is missing
> }
--
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