diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java index c06edb5e76..83ae0f87c7 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/ComponentMetadataGenerator.java @@ -27,7 +27,8 @@ public final class ComponentMetadataGenerator { EntityXmlMappingData xmlMappingData, boolean firstPass) { Component prop_component = (Component) value; - CompositeMapperBuilder componentMapper = mapper.addComponent(propertyAuditingData.getPropertyData()); + CompositeMapperBuilder componentMapper = mapper.addComponent(propertyAuditingData.getPropertyData(), + prop_component.getComponentClassName()); // The property auditing data must be for a component. ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData; diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java index 954f77dfcc..d386e8a199 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AnnotationsMetadataReader.java @@ -118,7 +118,7 @@ public final class AnnotationsMetadataReader { } new AuditedPropertiesReader(defaultStore, new PersistentClassPropertiesSource(xclass), auditData, - globalCfg, "").read(); + globalCfg, reflectionManager, "").read(); addAuditTable(xclass); addAuditSecondaryTables(xclass); diff --git a/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java b/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java index 33a63ea7d2..e5d92d1f12 100644 --- a/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java +++ b/envers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java @@ -13,6 +13,7 @@ import javax.persistence.Version; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XProperty; +import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.AuditOverride; import org.hibernate.envers.AuditOverrides; @@ -24,6 +25,7 @@ import org.hibernate.envers.tools.MappingTools; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; import org.hibernate.mapping.Value; +import org.hibernate.MappingException; import org.jboss.envers.Versioned; /** @@ -40,6 +42,7 @@ public class AuditedPropertiesReader { private final PersistentPropertiesSource persistentPropertiesSource; private final AuditedPropertiesHolder auditedPropertiesHolder; private final GlobalConfiguration globalCfg; + private final ReflectionManager reflectionManager; private final String propertyNamePrefix; private final Set propertyAccessedPersistentProperties; @@ -49,11 +52,13 @@ public class AuditedPropertiesReader { PersistentPropertiesSource persistentPropertiesSource, AuditedPropertiesHolder auditedPropertiesHolder, GlobalConfiguration globalCfg, + ReflectionManager reflectionManager, String propertyNamePrefix) { this.defaultStore = defaultStore; this.persistentPropertiesSource = persistentPropertiesSource; this.auditedPropertiesHolder = auditedPropertiesHolder; this.globalCfg = globalCfg; + this.reflectionManager = reflectionManager; this.propertyNamePrefix = propertyNamePrefix; propertyAccessedPersistentProperties = newHashSet(); @@ -104,9 +109,10 @@ public class AuditedPropertiesReader { isAudited = fillPropertyData(property, componentData, accessType); PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( - property.getType(), (Component) propertyValue); + (Component) propertyValue); new AuditedPropertiesReader(ModificationStore.FULL, componentPropertiesSource, componentData, - globalCfg, propertyNamePrefix+ MappingTools.createComponentPrefix(property.getName())) + globalCfg, reflectionManager, + propertyNamePrefix + MappingTools.createComponentPrefix(property.getName())) .read(); propertyData = componentData; @@ -251,12 +257,17 @@ public class AuditedPropertiesReader { public Class annotationType() { return this.getClass(); } }; - private static class ComponentPropertiesSource implements PersistentPropertiesSource { + private class ComponentPropertiesSource implements PersistentPropertiesSource { private final XClass xclass; private final Component component; - private ComponentPropertiesSource(XClass xclass, Component component) { - this.xclass = xclass; + private ComponentPropertiesSource(Component component) { + try { + this.xclass = reflectionManager.classForName(component.getComponentClassName(), this.getClass()); + } catch (ClassNotFoundException e) { + throw new MappingException(e); + } + this.component = component; } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java index 601fc50b34..c1fec96077 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java @@ -34,7 +34,6 @@ import org.hibernate.envers.reader.AuditReaderImplementor; import org.hibernate.envers.tools.reflection.ReflectionTools; import org.hibernate.collection.PersistentCollection; -import org.hibernate.property.Getter; import org.hibernate.property.Setter; import org.hibernate.util.ReflectHelper; @@ -42,20 +41,22 @@ import org.hibernate.util.ReflectHelper; * @author Adam Warski (adam at warski dot org) */ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperBuilder { - private PropertyData propertyData; - private ExtendedPropertyMapper delegate; + private final PropertyData propertyData; + private final ExtendedPropertyMapper delegate; + private final String componentClassName; - public ComponentPropertyMapper(PropertyData propertyData) { + public ComponentPropertyMapper(PropertyData propertyData, String componentClassName) { this.propertyData = propertyData; this.delegate = new MultiPropertyMapper(); + this.componentClassName = componentClassName; } public void add(PropertyData propertyData) { delegate.add(propertyData); } - public CompositeMapperBuilder addComponent(PropertyData propertyData) { - return delegate.addComponent(propertyData); + public CompositeMapperBuilder addComponent(PropertyData propertyData, String componentClassName) { + return delegate.addComponent(propertyData, componentClassName); } public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { @@ -71,11 +72,11 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB return; } - Getter getter = ReflectionTools.getGetter(obj.getClass(), propertyData); Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData); try { - Object subObj = ReflectHelper.getDefaultConstructor(getter.getReturnType()).newInstance(); + Object subObj = ReflectHelper.getDefaultConstructor( + Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance(); setter.set(obj, subObj, null); delegate.mapToEntityFromMap(verCfg, subObj, data, primaryKey, versionsReader, revision); } catch (Exception e) { diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java index f913201535..9998eaafe7 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/CompositeMapperBuilder.java @@ -29,6 +29,6 @@ import org.hibernate.envers.entities.PropertyData; * @author Adam Warski (adam at warski dot org) */ public interface CompositeMapperBuilder extends SimpleMapperBuilder { - public CompositeMapperBuilder addComponent(PropertyData propertyData); + public CompositeMapperBuilder addComponent(PropertyData propertyData, String componentClassName); public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper); } diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java index d80b6161e1..7e33c54b74 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/MultiPropertyMapper.java @@ -56,13 +56,13 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper { propertyDatas.put(propertyData.getName(), propertyData); } - public CompositeMapperBuilder addComponent(PropertyData propertyData) { + public CompositeMapperBuilder addComponent(PropertyData propertyData, String componentClassName) { if (properties.get(propertyData) != null) { // This is needed for second pass to work properly in the components mapper return (CompositeMapperBuilder) properties.get(propertyData); } - ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData); + ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData, componentClassName); addComposite(propertyData, componentMapperBuilder); return componentMapperBuilder; diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java index f5a393ee92..53bb93ea4c 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/SubclassPropertyMapper.java @@ -86,8 +86,8 @@ public class SubclassPropertyMapper implements ExtendedPropertyMapper { } } - public CompositeMapperBuilder addComponent(PropertyData propertyData) { - return main.addComponent(propertyData); + public CompositeMapperBuilder addComponent(PropertyData propertyData, String componentClassName) { + return main.addComponent(propertyData, componentClassName); } public void addComposite(PropertyData propertyData, PropertyMapper propertyMapper) { diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java new file mode 100644 index 0000000000..ad211f41cd --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/Component1.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.components; + +import javax.persistence.Embeddable; + +/** + * @author Adam Warski (adam at warski dot org) + */ +@Embeddable +public class Component1 implements IComponent { + private String data; + + public Component1(String data) { + this.data = data; + } + + public Component1() { + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Component1)) return false; + + Component1 that = (Component1) o; + + if (data != null ? !data.equals(that.data) : that.data != null) return false; + + return true; + } + + @Override + public int hashCode() { + return data != null ? data.hashCode() : 0; + } + + @Override + public String toString() { + return "Component1{" + + "data='" + data + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java new file mode 100644 index 0000000000..7444dede5f --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/ComponentTestEntity.java @@ -0,0 +1,102 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.components; + +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.envers.Audited; +import org.hibernate.annotations.Target; + +/** + * @author Adam Warski (adam at warski dot org) + */ +@Entity + @Audited +public class ComponentTestEntity { + @Id + @GeneratedValue + private Integer id; + + @Embedded + @Target(Component1.class) + private IComponent comp1; + + public ComponentTestEntity() { + } + + public ComponentTestEntity(IComponent comp1) { + this.comp1 = comp1; + } + + public ComponentTestEntity(Integer id, IComponent comp1) { + this.id = id; + this.comp1 = comp1; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public IComponent getComp1() { + return comp1; + } + + public void setComp1(IComponent comp1) { + this.comp1 = comp1; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ComponentTestEntity)) return false; + + ComponentTestEntity that = (ComponentTestEntity) o; + + if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (comp1 != null ? comp1.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ComponentTestEntity{" + + "id=" + id + + ", comp1=" + comp1 + + '}'; + } +} \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java new file mode 100644 index 0000000000..5b2413b88b --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/IComponent.java @@ -0,0 +1,9 @@ +package org.hibernate.envers.test.integration.interfaces.components; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface IComponent { + String getData(); + void setData(String data); +} diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java new file mode 100644 index 0000000000..692d0de893 --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/components/InterfacesComponents.java @@ -0,0 +1,95 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.components; + +import java.util.Arrays; +import javax.persistence.EntityManager; + +import org.hibernate.envers.test.AbstractEntityTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import org.hibernate.ejb.Ejb3Configuration; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class InterfacesComponents extends AbstractEntityTest { + private Integer id1; + + public void configure(Ejb3Configuration cfg) { + cfg.addAnnotatedClass(ComponentTestEntity.class); + } + + @BeforeClass(dependsOnMethods = "init") + public void initData() { + // Revision 1 + EntityManager em = getEntityManager(); + em.getTransaction().begin(); + + ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a")); + + em.persist(cte1); + + em.getTransaction().commit(); + + // Revision 2 + em = getEntityManager(); + em.getTransaction().begin(); + + cte1 = em.find(ComponentTestEntity.class, cte1.getId()); + + cte1.setComp1(new Component1("b")); + + em.getTransaction().commit(); + + // Revision 3 + em = getEntityManager(); + em.getTransaction().begin(); + + cte1 = em.find(ComponentTestEntity.class, cte1.getId()); + + cte1.getComp1().setData("c"); + + em.getTransaction().commit(); + + id1 = cte1.getId(); + } + + @Test + public void testRevisionsCounts() { + assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(ComponentTestEntity.class, id1)); + } + + @Test + public void testHistoryOfId1() { + ComponentTestEntity ver1 = new ComponentTestEntity(id1, new Component1("a")); + ComponentTestEntity ver2 = new ComponentTestEntity(id1, new Component1("b")); + ComponentTestEntity ver3 = new ComponentTestEntity(id1, new Component1("c")); + + assert getAuditReader().find(ComponentTestEntity.class, id1, 1).equals(ver1); + assert getAuditReader().find(ComponentTestEntity.class, id1, 2).equals(ver2); + assert getAuditReader().find(ComponentTestEntity.class, id1, 3).equals(ver3); + } +} \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/ISetRefEdEntity.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/ISetRefEdEntity.java new file mode 100644 index 0000000000..c8c9382c61 --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/ISetRefEdEntity.java @@ -0,0 +1,14 @@ +package org.hibernate.envers.test.integration.interfaces.relation; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public interface ISetRefEdEntity { + Integer getId(); + + void setId(Integer id); + + String getData(); + + void setData(String data); +} diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java new file mode 100644 index 0000000000..f2b51d20cd --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/InterfacesRelation.java @@ -0,0 +1,116 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.relation; + +import java.util.Arrays; +import javax.persistence.EntityManager; + +import org.hibernate.envers.test.AbstractEntityTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import org.hibernate.ejb.Ejb3Configuration; + +/** + * @author Adam Warski (adam at warski dot org) + */ +public class InterfacesRelation extends AbstractEntityTest { + private Integer ed1_id; + private Integer ed2_id; + + private Integer ing1_id; + + public void configure(Ejb3Configuration cfg) { + cfg.addAnnotatedClass(SetRefEdEntity.class); + cfg.addAnnotatedClass(SetRefIngEntity.class); + } + + @BeforeClass(dependsOnMethods = "init") + public void initData() { + EntityManager em = getEntityManager(); + + SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1"); + SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2"); + + SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1"); + + // Revision 1 + em.getTransaction().begin(); + + em.persist(ed1); + em.persist(ed2); + + em.getTransaction().commit(); + + // Revision 2 + + em.getTransaction().begin(); + + ed1 = em.find(SetRefEdEntity.class, ed1.getId()); + + ing1.setReference(ed1); + em.persist(ing1); + + em.getTransaction().commit(); + + // Revision 3 + em.getTransaction().begin(); + + ing1 = em.find(SetRefIngEntity.class, ing1.getId()); + ed2 = em.find(SetRefEdEntity.class, ed2.getId()); + + ing1.setReference(ed2); + + em.getTransaction().commit(); + + // + + ed1_id = ed1.getId(); + ed2_id = ed2.getId(); + + ing1_id = ing1.getId(); + } + + @Test + public void testRevisionsCounts() { + assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed1_id)); + assert Arrays.asList(1).equals(getAuditReader().getRevisions(SetRefEdEntity.class, ed2_id)); + + assert Arrays.asList(2, 3).equals(getAuditReader().getRevisions(SetRefIngEntity.class, ing1_id)); + } + + @Test + public void testHistoryOfEdIng1() { + SetRefEdEntity ed1 = getEntityManager().find(SetRefEdEntity.class, ed1_id); + SetRefEdEntity ed2 = getEntityManager().find(SetRefEdEntity.class, ed2_id); + + SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1); + SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2); + SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3); + + assert rev1 == null; + assert rev2.getReference().equals(ed1); + assert rev3.getReference().equals(ed2); + } +} \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java new file mode 100644 index 0000000000..ca1336da5c --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefEdEntity.java @@ -0,0 +1,93 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.relation; + +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.hibernate.envers.Audited; + +/** + * ReferencEd entity + * @author Adam Warski (adam at warski dot org) + */ +@Entity +@Audited +public class SetRefEdEntity implements ISetRefEdEntity { + @Id + private Integer id; + + private String data; + + public SetRefEdEntity() { + } + + public SetRefEdEntity(Integer id, String data) { + this.id = id; + this.data = data; + } + + public SetRefEdEntity(String data) { + this.data = data; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SetRefEdEntity)) return false; + + SetRefEdEntity that = (SetRefEdEntity) o; + + if (data != null ? !data.equals(that.data) : that.data != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) return false; + + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } + + public String toString() { + return "SetRefEdEntity(id = " + id + ", data = " + data + ")"; + } +} \ No newline at end of file diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java new file mode 100644 index 0000000000..995ad8caee --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/interfaces/relation/SetRefIngEntity.java @@ -0,0 +1,112 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, 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.interfaces.relation; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +import org.hibernate.envers.Audited; + +/** + * ReferencIng entity + * @author Adam Warski (adam at warski dot org) + */ +@Entity +public class SetRefIngEntity { + @Id + private Integer id; + + @Audited + private String data; + + @Audited + @ManyToOne(targetEntity = SetRefEdEntity.class) + private ISetRefEdEntity reference; + + public SetRefIngEntity() { } + + public SetRefIngEntity(Integer id, String data, ISetRefEdEntity reference) { + this.id = id; + this.data = data; + this.reference = reference; + } + + public SetRefIngEntity(String data, ISetRefEdEntity reference) { + this.data = data; + this.reference = reference; + } + + public SetRefIngEntity(Integer id, String data) { + this.id = id; + this.data = data; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public ISetRefEdEntity getReference() { + return reference; + } + + public void setReference(ISetRefEdEntity reference) { + this.reference = reference; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SetRefIngEntity)) return false; + + SetRefIngEntity that = (SetRefIngEntity) o; + + if (data != null ? !data.equals(that.data) : that.data != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) return false; + + return true; + } + + public int hashCode() { + int result; + result = (id != null ? id.hashCode() : 0); + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } + + public String toString() { + return "SetRefIngEntity(id = " + id + ", data = " + data + ")"; + } +} \ No newline at end of file diff --git a/envers/src/test/resources/testng.xml b/envers/src/test/resources/testng.xml index af3dd07750..41537b9fde 100644 --- a/envers/src/test/resources/testng.xml +++ b/envers/src/test/resources/testng.xml @@ -28,6 +28,8 @@ + +