[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7245) Inline natural-id synchronization doesn't consider objects loaded from shared cache

Guenther Demetz (JIRA) noreply at atlassian.com
Wed May 2 03:47:48 EDT 2012


    [ https://hibernate.onjira.com/browse/HHH-7245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46474#comment-46474 ] 

Guenther Demetz commented on HHH-7245:
--------------------------------------

New pull request is https://github.com/hibernate/hibernate-orm/pull/324

Sorry that I don't included also the test-case into the pull-request, I'm am still figthing with understanding github and so far I don't know how add commits to a pull-request, when there are further open pull-requests on the same branch.

Here following the instructions for the testcase: 
1. add following method in CachedMutableNaturalIdTest

{code:title=CachedMutableNaturalIdTest.java|borderStyle=solid}
@Test
@TestForIssue( jiraKey = "HHH-7245" )
	public void testNaturalIdChangeAfterResolveEntityFrom2LCache() {
		Session session = openSession();
		session.beginTransaction();
		AllCached it = new AllCached( "it" );
		
		session.save( it );
		Serializable id = it.getId();
		session.getTransaction().commit();
		session.close();

		session = openSession();
		session.beginTransaction();
		it = (AllCached) session.byId( AllCached.class ).load( id );

		it.setName( "it2" );
		it = (AllCached) session.bySimpleNaturalId( AllCached.class ).load( "it" );
		assertNull( it );
		it = (AllCached) session.bySimpleNaturalId( AllCached.class ).load( "it2" );
		assertNotNull( it );
		session.delete( it );
		session.getTransaction().commit();
		session.close();
	}
{code}

2. define class AllCached as follows:
{code:title=AllCached.java|borderStyle=solid}
/**
 * @author Guenther Demetz
 * Same as Another.class, excpect that here also the entity class itself is configured for shared cache
 */
@Entity
@NaturalIdCache
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AllCached {
	private Integer id;
	private String name;

	public AllCached() {
	}

	public AllCached(String name) {
		this.name = name;
	}

	@Id
	@GeneratedValue( generator = "increment" )
	@GenericGenerator( name = "increment", strategy = "increment" )
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@NaturalId(mutable = true)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
{code}

3. Add AllCached class to the getAnnotatedClasses array:

{code}
@Override
	protected Class<?>[] getAnnotatedClasses() {
		return new Class[] {Another.class, AllCached.class};
	}
{code}




> Inline natural-id synchronization doesn't consider objects loaded from shared cache
> -----------------------------------------------------------------------------------
>
>                 Key: HHH-7245
>                 URL: https://hibernate.onjira.com/browse/HHH-7245
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: caching (L2), core
>    Affects Versions: 4.1.2
>            Reporter: Guenther Demetz
>              Labels: 2L-Cache, NaturalId
>
> Similiar to HHH-7237.
> Inline natural-id synch process relies on all entity objects in persistence context having it's according natural-id values cached in the NaturalIdResolutionCache. While we assured that most scenarios, we forgot about entity loads from shared cache.

--
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