Author: adamw
Date: 2009-12-04 11:30:16 -0500 (Fri, 04 Dec 2009)
New Revision: 18136
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-4641:
- support for @PrimaryKeyJoinColumn on inherited entities
- test
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-04
10:44:57 UTC (rev 18135)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-04
16:30:16 UTC (rev 18136)
@@ -381,7 +381,7 @@
// Adding the "key" element with all columns + the revision
number column
Element keyMapping = mappingData.getFirst().addElement("key");
- MetadataTools.addColumns(keyMapping,
pc.getIdentifierProperty().getColumnIterator());
+ MetadataTools.addColumns(keyMapping,
pc.getTable().getPrimaryKey().columnIterator());
MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(),
null, 0, 0, null);
break;
Copied:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java
(from rev 18113,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java)
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java
(rev 0)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinAuditing.java 2009-12-04
16:30:16 UTC (rev 18136)
@@ -0,0 +1,105 @@
+/*
+ * 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.inheritance.joined.primarykeyjoin;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.testng.Assert;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.mapping.Column;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildPrimaryKeyJoinAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildPrimaryKeyJoinEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ id1 = 1;
+
+ // Rev 1
+ em.getTransaction().begin();
+ ChildPrimaryKeyJoinEntity ce = new ChildPrimaryKeyJoinEntity(id1, "x",
1l);
+ em.persist(ce);
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ ce = em.find(ChildPrimaryKeyJoinEntity.class, id1);
+ ce.setData("y");
+ ce.setNumber(2l);
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1,
2).equals(getAuditReader().getRevisions(ChildPrimaryKeyJoinEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ ChildPrimaryKeyJoinEntity ver1 = new ChildPrimaryKeyJoinEntity(id1,
"x", 1l);
+ ChildPrimaryKeyJoinEntity ver2 = new ChildPrimaryKeyJoinEntity(id1,
"y", 2l);
+
+ assert getAuditReader().find(ChildPrimaryKeyJoinEntity.class, id1,
1).equals(ver1);
+ assert getAuditReader().find(ChildPrimaryKeyJoinEntity.class, id1,
2).equals(ver2);
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ChildPrimaryKeyJoinEntity childVer1 = new ChildPrimaryKeyJoinEntity(id1,
"x", 1l);
+
+ assert
getAuditReader().createQuery().forEntitiesAtRevision(ChildPrimaryKeyJoinEntity.class,
1).getSingleResult()
+ .equals(childVer1);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class,
1).getSingleResult()
+ .equals(childVer1);
+ }
+
+ @Test
+ public void testChildIdColumnName() {
+ Assert.assertEquals("other_id",
+ ((Column) getCfg()
+
.getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD")
+ .getKey().getColumnIterator().next()).getName());
+ }
+}
\ No newline at end of file
Copied:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java
(from rev 18113,
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildEntity.java)
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java
(rev 0)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/primarykeyjoin/ChildPrimaryKeyJoinEntity.java 2009-12-04
16:30:16 UTC (rev 18136)
@@ -0,0 +1,82 @@
+/*
+ * 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.inheritance.joined.primarykeyjoin;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Audited
+@PrimaryKeyJoinColumn(name = "other_id")
+public class ChildPrimaryKeyJoinEntity extends ParentEntity {
+ @Basic
+ private Long number;
+
+ public ChildPrimaryKeyJoinEntity() {
+ }
+
+ public ChildPrimaryKeyJoinEntity(Integer id, String data, Long number) {
+ super(id, data);
+ this.number = number;
+ }
+
+ public Long getNumber() {
+ return number;
+ }
+
+ public void setNumber(Long number) {
+ this.number = number;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ChildPrimaryKeyJoinEntity)) return false;
+ if (!super.equals(o)) return false;
+
+ ChildPrimaryKeyJoinEntity childPrimaryKeyJoinEntity = (ChildPrimaryKeyJoinEntity)
o;
+
+ //noinspection RedundantIfStatement
+ if (number != null ? !number.equals(childPrimaryKeyJoinEntity.number) :
childPrimaryKeyJoinEntity.number != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (number != null ? number.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CPKJE(id = " + getId() + ", data = " + getData() +
", number = " + number + ")";
+ }
+}
\ No newline at end of file
Modified:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java 2009-12-04
10:44:57 UTC (rev 18135)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/single/ChildEntity.java 2009-12-04
16:30:16 UTC (rev 18136)
@@ -79,6 +79,6 @@
}
public String toString() {
- return "ChildEntity(id = " + getId() + ", data = " +
getData() + ", number = " + number + ")";
+ return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data =
" + getData() + ", number = " + number + ")";
}
}
\ No newline at end of file
Modified:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java 2009-12-04
10:44:57 UTC (rev 18135)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/tableperclass/ChildEntity.java 2009-12-04
16:30:16 UTC (rev 18136)
@@ -73,6 +73,6 @@
}
public String toString() {
- return "ChildEntity(id = " + getId() + ", data = " +
getData() + ", number = " + number + ")";
+ return "ChildPrimaryKeyJoinEntity(id = " + getId() + ", data =
" + getData() + ", number = " + number + ")";
}
}
\ No newline at end of file
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2009-12-04 10:44:57 UTC (rev 18135)
+++ core/trunk/envers/src/test/resources/testng.xml 2009-12-04 16:30:16 UTC (rev 18136)
@@ -18,6 +18,7 @@
<package
name="org.hibernate.envers.test.integration.inheritance.joined.childrelation"
/>
<package
name="org.hibernate.envers.test.integration.inheritance.joined.emptychild"
/>
<package
name="org.hibernate.envers.test.integration.inheritance.joined.notownedrelation"
/>
+ <package
name="org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin"
/>
<package
name="org.hibernate.envers.test.integration.inheritance.joined.relation" />
<package
name="org.hibernate.envers.test.integration.inheritance.joined.relation.unidirectional"
/>
<package
name="org.hibernate.envers.test.integration.inheritance.single" />