HHH-8908 : Column of Embedded missing in Audit Table
This commit is contained in:
parent
7e7a7b2f95
commit
700a233c41
|
@ -653,6 +653,7 @@ public final class CollectionMetadataGenerator {
|
|||
|
||||
new ComponentAuditedPropertiesReader(
|
||||
context,
|
||||
true, // true because the collection is being audited
|
||||
auditData,
|
||||
new AuditedPropertiesReader.ComponentPropertiesSource(
|
||||
context.getClassInfo( embeddableBinding.getAttributeContainer() ),
|
||||
|
|
|
@ -69,7 +69,7 @@ public final class AnnotationsMetadataReader {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
private ModificationStore getDefaultAudited(ClassInfo classInfo) {
|
||||
private ModificationStore getDefaultAuditedModStore(ClassInfo classInfo) {
|
||||
final AnnotationInstance audited = JandexHelper.getSingleAnnotation(
|
||||
classInfo.annotations(),
|
||||
EnversDotNames.AUDITED,
|
||||
|
@ -148,11 +148,12 @@ public final class AnnotationsMetadataReader {
|
|||
)
|
||||
);
|
||||
|
||||
ModificationStore defaultStore = getDefaultAudited( persistentClassPropertiesSource.getClassInfo() );
|
||||
ModificationStore defaultStore = getDefaultAuditedModStore( persistentClassPropertiesSource.getClassInfo() );
|
||||
auditData.setDefaultAudited( defaultStore != null );
|
||||
|
||||
new AuditedPropertiesReader(
|
||||
context,
|
||||
auditData.isAudited(),
|
||||
auditData,
|
||||
persistentClassPropertiesSource,
|
||||
""
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.hibernate.envers.event.spi.EnversDotNames;
|
|||
import org.hibernate.envers.internal.tools.MappingTools;
|
||||
import org.hibernate.envers.internal.tools.StringTools;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.reflite.spi.ClassDescriptor;
|
||||
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
|
||||
import org.hibernate.metamodel.source.internal.annotations.util.JandexHelper;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
|
@ -79,6 +80,7 @@ import static org.hibernate.envers.internal.tools.Tools.newHashSet;
|
|||
*/
|
||||
public class AuditedPropertiesReader {
|
||||
private final AuditConfiguration.AuditConfigurationContext context;
|
||||
private final boolean defaultAudited;
|
||||
// TODO: is AttributeBindingContainer actually needed or is Hierarchical sufficient?
|
||||
private final PersistentPropertiesSource processedPersistentPropertiesSource;
|
||||
private final ClassInfo processedClassInfo;
|
||||
|
@ -98,10 +100,12 @@ public class AuditedPropertiesReader {
|
|||
|
||||
public AuditedPropertiesReader(
|
||||
AuditConfiguration.AuditConfigurationContext context,
|
||||
boolean defaultAudited,
|
||||
AuditedPropertiesHolder auditedPropertiesHolder,
|
||||
PersistentPropertiesSource processedPersistentPropertiesSource,
|
||||
String propertyNamePrefix) {
|
||||
this.context = context;
|
||||
this.defaultAudited = defaultAudited;
|
||||
this.auditedPropertiesHolder = auditedPropertiesHolder;
|
||||
this.processedPersistentPropertiesSource = processedPersistentPropertiesSource;
|
||||
this.processedClassInfo = context.getClassInfo(
|
||||
|
@ -398,9 +402,20 @@ public class AuditedPropertiesReader {
|
|||
addFromProperties( getAttributeBindings( attributeBindingContainer, "field" ), "field", fieldAccessedPersistentProperties, allClassAudited );
|
||||
addFromProperties( getAttributeBindings( attributeBindingContainer, "property" ), "property", propertyAccessedPersistentProperties, allClassAudited );
|
||||
|
||||
if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) {
|
||||
if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() || defaultAudited ) {
|
||||
if ( Hierarchical.class.isInstance( attributeBindingContainer.getAttributeContainer() ) ) {
|
||||
// attributeBindingContainer *should* always be an Hierarchical
|
||||
final Hierarchical hierarchical = (Hierarchical) attributeBindingContainer.getAttributeContainer();
|
||||
final ClassDescriptor classDescriptor = (ClassDescriptor) hierarchical.getDescriptor();
|
||||
if ( !Object.class.getName().equals( classDescriptor.getSuperType().getName().toString() ) && hierarchical.getSuperType() == null ) {
|
||||
throw new NotYetImplementedException(
|
||||
String.format(
|
||||
"Inconsistency for [%s]; Hierarchical.getSuperType() is null but classDescriptor.getSuperType() is [%s]",
|
||||
attributeBindingContainer.getRoleBase().getFullPath(),
|
||||
classDescriptor.getSuperType().getName().toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( MappedSuperclass.class.isInstance( hierarchical.getSuperType() ) ) {
|
||||
throw new NotYetImplementedException( "@MappedSuperclass not supported with new metamodel by envers yet. " );
|
||||
}
|
||||
|
@ -466,7 +481,7 @@ public class AuditedPropertiesReader {
|
|||
// propertyValue
|
||||
// );
|
||||
// final AuditedPropertiesReader audPropReader = new AuditedPropertiesReader(
|
||||
// ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager,
|
||||
// defaultAudited, componentPropertiesSource, componentData, globalCfg, reflectionManager,
|
||||
// propertyNamePrefix + MappingTools.createComponentPrefix( embeddedName )
|
||||
// );
|
||||
// audPropReader.read();
|
||||
|
@ -496,6 +511,7 @@ public class AuditedPropertiesReader {
|
|||
|
||||
final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
|
||||
context,
|
||||
isAudited,
|
||||
componentData,
|
||||
componentPropertiesSource,
|
||||
propertyNamePrefix + MappingTools.createComponentPrefix( attributeBinding.getAttribute().getName() )
|
||||
|
|
|
@ -45,11 +45,12 @@ public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
|
|||
|
||||
public ComponentAuditedPropertiesReader(
|
||||
AuditConfiguration.AuditConfigurationContext context,
|
||||
boolean defaultAudited,
|
||||
AuditedPropertiesHolder auditedPropertiesHolder,
|
||||
PersistentPropertiesSource persistentPropertiesSource,
|
||||
String propertyNamePrefix) {
|
||||
super(
|
||||
context, auditedPropertiesHolder, persistentPropertiesSource, propertyNamePrefix
|
||||
context, defaultAudited, auditedPropertiesHolder, persistentPropertiesSource, propertyNamePrefix
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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.collections.mappedsuperclasselement;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
*/
|
||||
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.PROPERTY)
|
||||
public abstract class AbstractCode {
|
||||
/**
|
||||
* Initial Value
|
||||
*/
|
||||
protected static final int UNDEFINED = -1;
|
||||
|
||||
private int code = UNDEFINED;
|
||||
|
||||
protected AbstractCode() {
|
||||
this( UNDEFINED );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with code
|
||||
*/
|
||||
public AbstractCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + code;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
AbstractCode other = (AbstractCode) obj;
|
||||
if ( code != other.code ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.collections.mappedsuperclasselement;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
*/
|
||||
@Embeddable
|
||||
public class Code extends AbstractCode {
|
||||
|
||||
public Code() {
|
||||
}
|
||||
|
||||
public Code(int code) {
|
||||
super( code );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2014, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.collections.mappedsuperclasselement;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-8908" )
|
||||
@FailureExpectedWithNewMetamodel( message = "Aggregate.getSuperType() returns null when it should return a MappedSuperclass")
|
||||
public class CollectionOfMappedSuperclassComponentsTest extends BaseEnversJPAFunctionalTestCase {
|
||||
private Integer id1;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {MappedSuperclassComponentSetTestEntity.class, Code.class};
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
MappedSuperclassComponentSetTestEntity cte1 = new MappedSuperclassComponentSetTestEntity();
|
||||
|
||||
em.persist( cte1 );
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
cte1 = em.find( MappedSuperclassComponentSetTestEntity.class, cte1.getId() );
|
||||
|
||||
cte1.getComps().add( new Code( 1 ) );
|
||||
cte1.getCompsNotAudited().add( new Code( 100 ) );
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
id1 = cte1.getId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assertEquals(
|
||||
Arrays.asList( 1, 2 ),
|
||||
getAuditReader().getRevisions( MappedSuperclassComponentSetTestEntity.class, id1 )
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfId1() {
|
||||
MappedSuperclassComponentSetTestEntity entity = getAuditReader().find(
|
||||
MappedSuperclassComponentSetTestEntity.class,
|
||||
id1,
|
||||
1
|
||||
);
|
||||
assertEquals( 0, entity.getComps().size() );
|
||||
assertEquals( 0, entity.getCompsNotAudited().size() );
|
||||
|
||||
entity = getAuditReader().find( MappedSuperclassComponentSetTestEntity.class, id1, 2 );
|
||||
Set<Code> comps1 = entity.getComps();
|
||||
assertEquals( 1, comps1.size() );
|
||||
assertTrue( comps1.contains( new Code( 1 ) ) );
|
||||
// The contents of entity.getCompsNotAudited() is unspecified, so no need to test.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2014, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.collections.mappedsuperclasselement;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
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 org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.NotAudited;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class MappedSuperclassComponentSetTestEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "MCompTestEntityComps", joinColumns = @JoinColumn(name = "entity_id"))
|
||||
private Set<Code> comps = new HashSet<Code>();
|
||||
|
||||
@NotAudited
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "MCompTestEntityCompsNotAudited", joinColumns = @JoinColumn(name = "entity_id"))
|
||||
private Set<Code> compsNotAudited = new HashSet<Code>();
|
||||
|
||||
public MappedSuperclassComponentSetTestEntity() {
|
||||
}
|
||||
|
||||
public MappedSuperclassComponentSetTestEntity(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Set<Code> getComps() {
|
||||
return comps;
|
||||
}
|
||||
|
||||
public void setComps(Set<Code> comps) {
|
||||
this.comps = comps;
|
||||
}
|
||||
|
||||
public Set<Code> getCompsNotAudited() {
|
||||
return compsNotAudited;
|
||||
}
|
||||
|
||||
public void setCompsNotAudited(Set<Code> comps) {
|
||||
this.compsNotAudited = compsNotAudited;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !(o instanceof MappedSuperclassComponentSetTestEntity ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MappedSuperclassComponentSetTestEntity that = (MappedSuperclassComponentSetTestEntity) o;
|
||||
|
||||
if ( comps != null ? !comps.equals( that.comps ) : that.comps != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (comps != null ? comps.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ComponentSetTestEntity{" +
|
||||
"id=" + id +
|
||||
", comps=" + comps +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
*/
|
||||
|
||||
@MappedSuperclass
|
||||
@Access(AccessType.FIELD)
|
||||
public abstract class AbstractEmbeddable {
|
||||
|
||||
/**
|
||||
* Initial Value
|
||||
*/
|
||||
protected static final int UNDEFINED = -1;
|
||||
|
||||
private int code = UNDEFINED;
|
||||
|
||||
|
||||
protected AbstractEmbeddable() {
|
||||
this( UNDEFINED );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with code
|
||||
*/
|
||||
public AbstractEmbeddable(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + code;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
AbstractEmbeddable other = (AbstractEmbeddable) obj;
|
||||
if ( code != other.code ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class EmbeddableWithDeclaredData extends AbstractEmbeddable {
|
||||
|
||||
private String codeArt;
|
||||
|
||||
public EmbeddableWithDeclaredData(int code, String codeArt) {
|
||||
super( code );
|
||||
this.codeArt = codeArt;
|
||||
}
|
||||
|
||||
// Needed for @Embeddable
|
||||
protected EmbeddableWithDeclaredData() {
|
||||
this( UNDEFINED, null );
|
||||
}
|
||||
|
||||
public String getCodeart() {
|
||||
return codeArt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ( ( codeArt == null ) ? 0 : codeArt.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( !super.equals( obj ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
EmbeddableWithDeclaredData other = (EmbeddableWithDeclaredData) obj;
|
||||
if ( codeArt == null ) {
|
||||
if ( other.codeArt != null ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( !codeArt.equals( other.codeArt ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-8908")
|
||||
@FailureExpectedWithNewMetamodel( message = "Aggregate.getSuperType() returns null when it should return a MappedSuperclass")
|
||||
public class EmbeddableWithDeclaredDataTest extends BaseEnversJPAFunctionalTestCase {
|
||||
private long id;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { EntityWithEmbeddableWithDeclaredData.class, AbstractEmbeddable.class, EmbeddableWithDeclaredData.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
EntityWithEmbeddableWithDeclaredData entity = new EntityWithEmbeddableWithDeclaredData();
|
||||
entity.setName( "Entity 1" );
|
||||
entity.setValue( new EmbeddableWithDeclaredData( 42, "TestCodeart" ) );
|
||||
|
||||
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();
|
||||
EntityWithEmbeddableWithDeclaredData entityLoaded = em.find( EntityWithEmbeddableWithDeclaredData.class, id );
|
||||
|
||||
AuditReader reader = AuditReaderFactory.get( em );
|
||||
|
||||
List<Number> revs = reader.getRevisions( EntityWithEmbeddableWithDeclaredData.class, id );
|
||||
Assert.assertEquals( 1, revs.size() );
|
||||
|
||||
EntityWithEmbeddableWithDeclaredData entityRev1 = reader.find( EntityWithEmbeddableWithDeclaredData.class, id, revs.get( 0 ) );
|
||||
|
||||
Assert.assertEquals( entityLoaded.getName(), entityRev1.getName() );
|
||||
|
||||
// value is read from AUD Table
|
||||
Assert.assertEquals( entityLoaded.getValue(), entityRev1.getValue() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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.Embeddable;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@Embeddable
|
||||
public class EmbeddableWithNoDeclaredData extends AbstractEmbeddable {
|
||||
|
||||
public EmbeddableWithNoDeclaredData(int code) {
|
||||
super( code );
|
||||
}
|
||||
|
||||
// Needed for @Embeddable
|
||||
protected EmbeddableWithNoDeclaredData() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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.FailureExpectedWithNewMetamodel;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* @author Jakob Braeuchi.
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-8908")
|
||||
@FailureExpectedWithNewMetamodel( message = "Aggregate.getSuperType() returns null when it should return a MappedSuperclass")
|
||||
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() );
|
||||
}
|
||||
}
|
|
@ -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 EntityWithEmbeddableWithDeclaredData {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
@Column(name = "NAME", length = 100)
|
||||
private String name;
|
||||
|
||||
@Embedded
|
||||
private EmbeddableWithDeclaredData 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 EmbeddableWithDeclaredData getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(EmbeddableWithDeclaredData 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;
|
||||
}
|
||||
EntityWithEmbeddableWithDeclaredData other = (EntityWithEmbeddableWithDeclaredData) obj;
|
||||
if ( id != other.id ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue