HHH-8968 - Fix and test by FiatLox

This commit is contained in:
Lukasz Antoniak 2014-02-24 22:18:08 +01:00
parent 34a45c5722
commit 3b2a09d2e7
3 changed files with 36 additions and 12 deletions

View File

@ -118,7 +118,12 @@ public class MiddleEmbeddableComponentMapper implements MiddleComponentMapper, C
);
}
else {
parameters.addWhere( prefix1 + '.' + propertyName, false, "=", prefix2 + '.' + propertyName, false );
// (p1.prop = p2.prop or (p1.prop is null and p2.prop is null))
Parameters sub1 = parameters.addSubParameters( "or" );
sub1.addWhere( prefix1 + '.' + propertyName, false, "=", prefix2 + '.' + propertyName, false );
Parameters sub2 = sub1.addSubParameters( "and" );
sub2.addNullRestriction( prefix1 + '.' + propertyName, false );
sub2.addNullRestriction( prefix2 + '.' + propertyName, false );
}
}
}

View File

@ -23,10 +23,12 @@
*/
package org.hibernate.envers.test.entities.components;
import javax.persistence.Embedded;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import java.util.HashSet;
import java.util.Set;
@ -42,8 +44,8 @@ public class ComponentSetTestEntity {
@GeneratedValue
private Integer id;
@Embedded
@Audited
@ElementCollection
@CollectionTable(name = "CompTestEntityComps", joinColumns = @JoinColumn(name = "entity_id"))
private Set<Component1> comps = new HashSet<Component1>();
public ComponentSetTestEntity() {

View File

@ -25,6 +25,7 @@ package org.hibernate.envers.test.integration.components.collections;
import javax.persistence.EntityManager;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
@ -32,17 +33,20 @@ import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.components.Component1;
import org.hibernate.envers.test.entities.components.ComponentSetTestEntity;
import org.junit.Ignore;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* TODO: enable and implement
*
* @author Adam Warski (adam at warski dot org)
* @author Felix Feisst
*/
@Ignore
public class CollectionOfComponents extends BaseEnversJPAFunctionalTestCase {
private Integer id1;
private Integer id2;
@Override
protected Class<?>[] getAnnotatedClasses() {
@ -58,6 +62,10 @@ public class CollectionOfComponents extends BaseEnversJPAFunctionalTestCase {
ComponentSetTestEntity cte1 = new ComponentSetTestEntity();
ComponentSetTestEntity cte2 = new ComponentSetTestEntity();
cte2.getComps().add( new Component1( "string1", null ) );
em.persist( cte2 );
em.persist( cte1 );
em.getTransaction().commit();
@ -73,19 +81,28 @@ public class CollectionOfComponents extends BaseEnversJPAFunctionalTestCase {
em.getTransaction().commit();
id1 = cte1.getId();
id2 = cte2.getId();
}
@Test
public void testRevisionsCounts() {
assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( ComponentSetTestEntity.class, id1 ) );
assertEquals( Arrays.asList( 1, 2 ), getAuditReader().getRevisions( ComponentSetTestEntity.class, id1 ) );
}
@Test
public void testHistoryOfId1() {
assert getAuditReader().find( ComponentSetTestEntity.class, id1, 1 ).getComps().size() == 0;
assertEquals( 0, getAuditReader().find( ComponentSetTestEntity.class, id1, 1 ).getComps().size() );
Set<Component1> comps1 = getAuditReader().find( ComponentSetTestEntity.class, id1, 2 ).getComps();
assert comps1.size() == 1;
assert comps1.contains( new Component1( "a", "b" ) );
assertEquals( 1, comps1.size() );
assertTrue( comps1.contains( new Component1( "a", "b" ) ) );
}
@Test
@TestForIssue(jiraKey = "HHH-8968")
public void testCollectionOfEmbeddableWithNullValue() {
final Component1 componentV1 = new Component1( "string1", null );
final ComponentSetTestEntity entityV1 = getAuditReader().find( ComponentSetTestEntity.class, id2, 1 );
assertEquals( "Expected a component", Collections.singleton( componentV1 ), entityV1.getComps() );
}
}