[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7235) Support null NaturalId values in loadEntityIdByNaturalId query

Guenther Demetz (JIRA) noreply at atlassian.com
Tue Apr 10 04:04:48 EDT 2012


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

Guenther Demetz commented on HHH-7235:
--------------------------------------

Following the according test-method to add in the matrix test.
It tests naturalId lookup on a null String value and on a null Entity value

{code:title=org.hibernate.test.naturalid.nullable.NullableNaturalIdTest.java|borderStyle=solid}

...
        @Override
	protected Class<?>[] getAnnotatedClasses() {
		return new Class[] {  C.class, D.class };
	}
...
        @Test
	public void testNaturalIdQuerySupportingNullValues() {
		Session session = openSession();
		session.beginTransaction();
		D d1 = new D();
		d1.name="Titi";
		d1.associatedC = null; 
		
		D d2 = new D();
		d2.name=null;
		
		C c = new C();
		d2.associatedC = c; 
		
		
		
		session.persist( d1 );
		session.persist( d2 );
		session.persist( c );
		session.getTransaction().commit();
		session.close();

		session = openSession();
		session.beginTransaction();
		
		
		assertNotNull( session.byNaturalId(D.class).using("name", null).using("associatedC", c).load());
		
		assertNotNull( session.byNaturalId(D.class).using("name", "Titi").using("associatedC", null).load());
		session.getTransaction().commit();
		session.close();
	}


{code}


New entity class D

{code:title=org.hibernate.test.naturalid.nullable.D.java|borderStyle=solid}
package org.hibernate.test.naturalid.nullable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.NaturalId;

/**
 * @author Guenther Demetz
 */
@Entity
public class D {
	@Id @GeneratedValue(strategy = GenerationType.TABLE)
	public long oid;
	
	@NaturalId(mutable=true)
	public String name;

	@NaturalId(mutable=true)
	@ManyToOne
	public C associatedC;
}
{code}

> Support null NaturalId values in loadEntityIdByNaturalId query
> --------------------------------------------------------------
>
>                 Key: HHH-7235
>                 URL: https://hibernate.onjira.com/browse/HHH-7235
>             Project: Hibernate ORM
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 4.1.0, 4.1.1, 4.1.2
>            Reporter: Guenther Demetz
>              Labels: naturalId
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> As it is allowed to persist and commit null naturalId values (for example null String values),
> it would also be nice to can sucessful lookup for those values.
> Currently the where-clause of the lookup-query does not consider the eventuality of null values, which in sql require an extra handling (using 'is' keyword instead of '=' sign).
> The needed code change is simple, see pull request.

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