Author: adamw
Date: 2009-12-07 03:36:49 -0500 (Mon, 07 Dec 2009)
New Revision: 18150
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
Log:
HHH-4644:
- when using join-inheritance, the columns in child entities which map to the revision
number use the correct sql-type
- test
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07
06:58:40 UTC (rev 18149)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07
08:36:49 UTC (rev 18150)
@@ -61,7 +61,7 @@
private Type revisionInfoTimestampType;
private String revisionPropType;
- private Column revisionPropColumn;
+ private String revisionPropSqlType;
public RevisionInfoConfiguration() {
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
@@ -97,9 +97,9 @@
rev_rel_mapping.addAttribute("type", revisionPropType);
rev_rel_mapping.addAttribute("class", revisionInfoEntityName);
- if (revisionPropColumn != null) {
+ if (revisionPropSqlType != null) {
// Putting a fake name to make Hibernate happy. It will be replaced later
anyway.
- MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0,
revisionPropColumn.columnDefinition());
+ MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0,
revisionPropSqlType);
}
return rev_rel_mapping;
@@ -137,7 +137,10 @@
// Getting the @Column definition of the revision number property, to
later use that info to
// generate the same mapping for the relation from an audit table's
revision number to the
// revision entity revision number.
- revisionPropColumn = property.getAnnotation(Column.class);
+ Column revisionPropColumn = property.getAnnotation(Column.class);
+ if (revisionPropColumn != null) {
+ revisionPropSqlType = revisionPropColumn.columnDefinition();
+ }
}
if (revisionTimestamp != null) {
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-07
06:58:40 UTC (rev 18149)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-07
08:36:49 UTC (rev 18150)
@@ -95,15 +95,24 @@
entitiesJoins = new HashMap<String, Map<Join, Element>>();
}
- void addRevisionInfoRelation(Element any_mapping) {
+ /**
+ * Clones the revision info relation mapping, so that it can be added to other
mappings. Also, the name of
+ * the property and the column are set properly.
+ * @return A revision info mapping, which can be added to other mappings (has no
parent).
+ */
+ private Element cloneAndSetupRevisionInfoRelationMapping() {
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
MetadataTools.addOrModifyColumn(rev_mapping, verEntCfg.getRevisionFieldName());
- any_mapping.add(rev_mapping);
+ return rev_mapping;
}
+ void addRevisionInfoRelation(Element any_mapping) {
+ any_mapping.add(cloneAndSetupRevisionInfoRelationMapping());
+ }
+
void addRevisionType(Element any_mapping) {
Element revTypeProperty = MetadataTools.addProperty(any_mapping,
verEntCfg.getRevisionTypePropName(),
verEntCfg.getRevisionTypePropType(), true, false);
@@ -379,10 +388,12 @@
case JOINED:
mappingData = generateInheritanceMappingData(pc, xmlMappingData,
auditTableData, "joined-subclass");
- // Adding the "key" element with all columns + the revision
number column
+ // Adding the "key" element with all id columns...
Element keyMapping = mappingData.getFirst().addElement("key");
MetadataTools.addColumns(keyMapping,
pc.getTable().getPrimaryKey().columnIterator());
- MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(),
null, 0, 0, null);
+
+ // ... and the revision number column, read from the revision info
relation mapping.
+ keyMapping.add((Element)
cloneAndSetupRevisionInfoRelationMapping().element("column").clone());
break;
case TABLE_PER_CLASS:
Copied:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.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/reventity/LongRevEntityInheritanceChildAuditing.java
(rev 0)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java 2009-12-07
08:36:49 UTC (rev 18150)
@@ -0,0 +1,61 @@
+/*
+ * 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.reventity;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity;
+import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
+import org.hibernate.mapping.Column;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Iterator;
+
+/**
+ * A join-inheritance test using a custom revision entity where the revision number is a
long, mapped in the database
+ * as an int.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class LongRevEntityInheritanceChildAuditing extends AbstractEntityTest {
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @Test
+ public void testChildRevColumnType() {
+ // We need the second column
+ Iterator childEntityKeyColumnsIterator = getCfg()
+
.getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD")
+ .getKey()
+ .getColumnIterator();
+ childEntityKeyColumnsIterator.next();
+ Column second = (Column) childEntityKeyColumnsIterator.next();
+
+ assertEquals(second.getSqlType(), "int");
+ }
+}
\ No newline at end of file
Modified:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07
06:58:40 UTC (rev 18149)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07
08:36:49 UTC (rev 18150)
@@ -26,6 +26,7 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Column;
import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
@@ -40,6 +41,7 @@
@Id
@GeneratedValue
@RevisionNumber
+ @Column(columnDefinition = "int")
private long customId;
@RevisionTimestamp