Permalink
Browse files

HHH-8968 - Fix and test by FiatLox

  • Loading branch information...
lukasz-antoniak committed Feb 24, 2014
1 parent a373505 commit d28447ee933e270ac8e671a0857045118187448b
@@ -118,7 +118,12 @@ else if ( nestedMapper instanceof ToOneIdMapper ) {
);
}
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 );
}
}
}
@@ -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 @@
@GeneratedValue
private Integer id;
- @Embedded
- @Audited
+ @ElementCollection
+ @CollectionTable(name = "CompTestEntityComps", joinColumns = @JoinColumn(name = "entity_id"))
private Set<Component1> comps = new HashSet<Component1>();
public ComponentSetTestEntity() {
@@ -25,24 +25,28 @@
import javax.persistence.EntityManager;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Set;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
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 void initData() {
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 void initData() {
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() );
}
}

0 comments on commit d28447e

Please sign in to comment.