HHH-8908 : Column of Embedded missing in Audit Table; reorg tests

This commit is contained in:
Gail Badner 2014-04-17 13:55:01 -07:00
parent b3b2312482
commit f693f5c320
8 changed files with 228 additions and 78 deletions

View File

@ -97,6 +97,6 @@ public class CollectionOfMappedSuperclassComponentsTest extends BaseEnversJPAFun
Set<Code> comps1 = entity.getComps(); Set<Code> comps1 = entity.getComps();
assertEquals( 1, comps1.size() ); assertEquals( 1, comps1.size() );
assertTrue( comps1.contains( new Code( 1 ) ) ); assertTrue( comps1.contains( new Code( 1 ) ) );
assertEquals( 0, entity.getCompsNotAudited().size() ); // The contents of entity.getCompsNotAudited() is unspecified, so no need to test.
} }
} }

View File

@ -33,7 +33,7 @@ import javax.persistence.MappedSuperclass;
@MappedSuperclass @MappedSuperclass
@Access(AccessType.FIELD) @Access(AccessType.FIELD)
public abstract class AbstractCode { public abstract class AbstractEmbeddable {
/** /**
* Initial Value * Initial Value
@ -43,19 +43,17 @@ public abstract class AbstractCode {
private int code = UNDEFINED; private int code = UNDEFINED;
protected AbstractCode() { protected AbstractEmbeddable() {
this( UNDEFINED ); this( UNDEFINED );
} }
/** /**
* Constructor with code * Constructor with code
*/ */
public AbstractCode(int code) { public AbstractEmbeddable(int code) {
this.code = code; this.code = code;
} }
public abstract String getCodeart();
public int getCode() { public int getCode() {
return code; return code;
} }
@ -79,7 +77,7 @@ public abstract class AbstractCode {
if ( getClass() != obj.getClass() ) { if ( getClass() != obj.getClass() ) {
return false; return false;
} }
AbstractCode other = (AbstractCode) obj; AbstractEmbeddable other = (AbstractEmbeddable) obj;
if ( code != other.code ) { if ( code != other.code ) {
return false; return false;
} }

View File

@ -25,26 +25,26 @@ package org.hibernate.envers.test.integration.components.mappedsuperclass;
/** /**
* @author Jakob Braeuchi. * @author Jakob Braeuchi.
* @author Gail Badner
*/ */
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
@Embeddable @Embeddable
public class Code extends AbstractCode { public class EmbeddableWithDeclaredData extends AbstractEmbeddable {
private String codeArt; private String codeArt;
public Code(int code, String codeArt) { public EmbeddableWithDeclaredData(int code, String codeArt) {
super( code ); super( code );
this.codeArt = codeArt; this.codeArt = codeArt;
} }
// Needed for @Embeddable // Needed for @Embeddable
protected Code() { protected EmbeddableWithDeclaredData() {
this( UNDEFINED, null ); this( UNDEFINED, null );
} }
@Override
public String getCodeart() { public String getCodeart() {
return codeArt; return codeArt;
} }
@ -68,7 +68,7 @@ public class Code extends AbstractCode {
if ( getClass() != obj.getClass() ) { if ( getClass() != obj.getClass() ) {
return false; return false;
} }
Code other = (Code) obj; EmbeddableWithDeclaredData other = (EmbeddableWithDeclaredData) obj;
if ( codeArt == null ) { if ( codeArt == null ) {
if ( other.codeArt != null ) { if ( other.codeArt != null ) {
return false; return false;

View File

@ -38,14 +38,15 @@ import org.hibernate.testing.TestForIssue;
/** /**
* @author Jakob Braeuchi. * @author Jakob Braeuchi.
* @author Gail Badner
*/ */
@TestForIssue(jiraKey = "HHH-8908") @TestForIssue(jiraKey = "HHH-8908")
public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestCase { public class EmbeddableWithDeclaredDataTest extends BaseEnversJPAFunctionalTestCase {
private long id; private long id;
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class[] { SimplePerson.class, AbstractCode.class, Code.class, TestCode.class }; return new Class[] { EntityWithEmbeddableWithDeclaredData.class, AbstractEmbeddable.class, EmbeddableWithDeclaredData.class };
} }
@Test @Test
@ -53,18 +54,17 @@ public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestC
public void initData() { public void initData() {
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
SimplePerson person = new SimplePerson(); EntityWithEmbeddableWithDeclaredData entity = new EntityWithEmbeddableWithDeclaredData();
person.setName( "Person 1" ); entity.setName( "Entity 1" );
person.setTestCode( new TestCode( 84 ) ); entity.setValue( new EmbeddableWithDeclaredData( 42, "TestCodeart" ) );
person.setGenericCode( new Code( 42, "TestCodeart" ) );
EntityTransaction tx = em.getTransaction(); EntityTransaction tx = em.getTransaction();
tx.begin(); tx.begin();
em.persist( person ); em.persist( entity );
tx.commit(); tx.commit();
em.close(); em.close();
id = person.getId(); id = entity.getId();
} }
@Test @Test
@ -72,21 +72,18 @@ public class MappedSuperclassEmbeddableTest extends BaseEnversJPAFunctionalTestC
// Reload and Compare Revision // Reload and Compare Revision
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
SimplePerson personLoaded = em.find( SimplePerson.class, id ); EntityWithEmbeddableWithDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em ); AuditReader reader = AuditReaderFactory.get( em );
List<Number> revs = reader.getRevisions( SimplePerson.class, id ); List<Number> revs = reader.getRevisions( EntityWithEmbeddableWithDeclaredData.class, id );
Assert.assertEquals( 1, revs.size() ); Assert.assertEquals( 1, revs.size() );
SimplePerson personRev1 = reader.find( SimplePerson.class, id, revs.get( 0 ) ); EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithDeclaredData.class, id, revs.get( 0 ) );
Assert.assertEquals( personLoaded.getName(), personRev1.getName() ); Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// Generic Code is read from AUD Table // value is read from AUD Table
Assert.assertEquals( personLoaded.getGenericCode(), personRev1.getGenericCode() ); Assert.assertEquals( entityLoaded.getValue(), entityRev1.getValue() );
// Test Code is read from AUD Table
Assert.assertEquals( personLoaded.getTestCode(), personRev1.getTestCode() );
} }
} }

View File

@ -28,26 +28,16 @@ import javax.persistence.Transient;
/** /**
* @author Jakob Braeuchi. * @author Jakob Braeuchi.
* @author Gail Badner
*/ */
@Embeddable @Embeddable
public class TestCode extends AbstractCode { public class EmbeddableWithNoDeclaredData extends AbstractEmbeddable {
public static final int _TEST = 1; public EmbeddableWithNoDeclaredData(int code) {
public static final TestCode TEST = new TestCode( _TEST );
public TestCode(int code) {
super( code ); super( code );
} }
// Needed for @Embeddable // Needed for @Embeddable
protected TestCode() { protected EmbeddableWithNoDeclaredData() {
super( UNDEFINED );
}
@Override
@Transient
public String getCodeart() {
return "TestCode";
} }
} }

View File

@ -0,0 +1,89 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.test.integration.components.mappedsuperclass;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.junit.Assert;
import org.junit.Test;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.testing.TestForIssue;
/**
* @author Jakob Braeuchi.
* @author Gail Badner
*/
@TestForIssue(jiraKey = "HHH-8908")
public class EmbeddableWithNoDeclaredDataTest extends BaseEnversJPAFunctionalTestCase {
private long id;
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { EntityWithEmbeddableWithNoDeclaredData.class, AbstractEmbeddable.class, EmbeddableWithNoDeclaredData.class };
}
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
EntityWithEmbeddableWithNoDeclaredData entity = new EntityWithEmbeddableWithNoDeclaredData();
entity.setName( "Entity 1" );
entity.setValue( new EmbeddableWithNoDeclaredData( 84 ) );
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist( entity );
tx.commit();
em.close();
id = entity.getId();
}
@Test
public void testEmbeddableThatExtendsMappedSuperclass() {
// Reload and Compare Revision
EntityManager em = getEntityManager();
EntityWithEmbeddableWithNoDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithNoDeclaredData.class, id );
AuditReader reader = AuditReaderFactory.get( em );
List<Number> revs = reader.getRevisions( EntityWithEmbeddableWithNoDeclaredData.class, id );
Assert.assertEquals( 1, revs.size() );
EntityWithEmbeddableWithNoDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithNoDeclaredData.class, id, revs.get( 0 ) );
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
// value is read from AUD Table
Assert.assertEquals( entityLoaded.getValue(), entityRev1.getValue() );
}
}

View File

@ -26,15 +26,11 @@ package org.hibernate.envers.test.integration.components.mappedsuperclass;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embedded; import javax.persistence.Embedded;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
@ -42,31 +38,19 @@ import org.hibernate.envers.Audited;
* @author Jakob Braeuchi. * @author Jakob Braeuchi.
*/ */
@Entity @Entity
@Table(name = "TEST_SIMPLE_PERSON")
@Access(AccessType.FIELD) @Access(AccessType.FIELD)
@Audited @Audited
public class SimplePerson { public class EntityWithEmbeddableWithDeclaredData {
@Id @Id
@GeneratedValue @GeneratedValue
private long id; private long id;
@Version
private long version;
@Column(name = "NAME", length = 100) @Column(name = "NAME", length = 100)
private String name; private String name;
@Embedded @Embedded
@AttributeOverrides({ @AttributeOverride(name = "code", column = @Column(name = "THE_TEST")) }) private EmbeddableWithDeclaredData value;
private TestCode testCode = TestCode.TEST;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "code", column = @Column(name = "THE_CODE")),
@AttributeOverride(name = "codeArt", column = @Column(name = "THE_CODEART"))
})
private Code genericCode;
public long getId() { public long getId() {
return id; return id;
@ -76,10 +60,6 @@ public class SimplePerson {
this.id = id; this.id = id;
} }
public long getVersion() {
return version;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -88,20 +68,12 @@ public class SimplePerson {
this.name = name; this.name = name;
} }
public TestCode getTestCode() { public EmbeddableWithDeclaredData getValue() {
return testCode; return value;
} }
public void setTestCode(TestCode testCode) { public void setValue(EmbeddableWithDeclaredData value) {
this.testCode = testCode; this.value = value;
}
public Code getGenericCode() {
return genericCode;
}
public void setGenericCode(Code genericCode) {
this.genericCode = genericCode;
} }
@Override @Override
@ -123,7 +95,7 @@ public class SimplePerson {
if ( getClass() != obj.getClass() ) { if ( getClass() != obj.getClass() ) {
return false; return false;
} }
SimplePerson other = (SimplePerson) obj; EntityWithEmbeddableWithDeclaredData other = (EntityWithEmbeddableWithDeclaredData) obj;
if ( id != other.id ) { if ( id != other.id ) {
return false; return false;
} }

View File

@ -0,0 +1,104 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.test.integration.components.mappedsuperclass;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.envers.Audited;
/**
* @author Jakob Braeuchi.
*/
@Entity
@Access(AccessType.FIELD)
@Audited
public class EntityWithEmbeddableWithNoDeclaredData {
@Id
@GeneratedValue
private long id;
@Column(name = "NAME", length = 100)
private String name;
@Embedded
private EmbeddableWithNoDeclaredData value;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public EmbeddableWithNoDeclaredData getValue() {
return value;
}
public void setValue(EmbeddableWithNoDeclaredData value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) ( id ^ ( id >>> 32 ) );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
EntityWithEmbeddableWithNoDeclaredData other = (EntityWithEmbeddableWithNoDeclaredData) obj;
if ( id != other.id ) {
return false;
}
return true;
}
}