parent
00849bce2e
commit
ec7993e20e
|
@ -93,7 +93,7 @@ public class RevisionInfoConfiguration {
|
|||
private Document generateDefaultRevisionInfoXmlMapping() {
|
||||
Document document = XMLHelper.getDocumentFactory().createDocument();
|
||||
|
||||
Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()), null);
|
||||
Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()), null, null);
|
||||
|
||||
class_mapping.addAttribute("name", revisionInfoEntityName);
|
||||
class_mapping.addAttribute("table", "REVINFO");
|
||||
|
|
|
@ -362,7 +362,7 @@ public final class AuditMetadataGenerator {
|
|||
PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData,
|
||||
IdMappingData idMapper) {
|
||||
Element class_mapping = MetadataTools.createEntity(xmlMappingData.getMainXmlMapping(), auditTableData,
|
||||
pc.getDiscriminatorValue());
|
||||
pc.getDiscriminatorValue(), pc.isAbstract());
|
||||
ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper();
|
||||
|
||||
// Checking if there is a discriminator column
|
||||
|
@ -387,7 +387,7 @@ public final class AuditMetadataGenerator {
|
|||
String inheritanceMappingType) {
|
||||
String extendsEntityName = verEntCfg.getAuditEntityName(pc.getSuperclass().getEntityName());
|
||||
Element class_mapping = MetadataTools.createSubclassEntity(xmlMappingData.getMainXmlMapping(),
|
||||
inheritanceMappingType, auditTableData, extendsEntityName, pc.getDiscriminatorValue());
|
||||
inheritanceMappingType, auditTableData, extendsEntityName, pc.getDiscriminatorValue(), pc.isAbstract());
|
||||
|
||||
// The id and revision type is already mapped in the parent
|
||||
|
||||
|
|
|
@ -531,7 +531,7 @@ public final class CollectionMetadataGenerator {
|
|||
String catalog = mainGenerator.getCatalog(propertyAuditingData.getJoinTable().catalog(), propertyValue.getCollectionTable());
|
||||
|
||||
Element middleEntityXml = MetadataTools.createEntity(xmlMappingData.newAdditionalMapping(),
|
||||
new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null);
|
||||
new AuditTableData(auditMiddleEntityName, auditMiddleTableName, schema, catalog), null, null);
|
||||
Element middleEntityXmlId = middleEntityXml.addElement("composite-id");
|
||||
|
||||
// If there is a where clause on the relation, adding it to the middle entity.
|
||||
|
|
|
@ -157,7 +157,7 @@ public class MetadataTools {
|
|||
}
|
||||
|
||||
private static Element createEntityCommon(Document document, String type, AuditTableData auditTableData,
|
||||
String discriminatorValue) {
|
||||
String discriminatorValue, Boolean isAbstract) {
|
||||
Element hibernate_mapping = document.addElement("hibernate-mapping");
|
||||
hibernate_mapping.addAttribute("auto-import", "false");
|
||||
|
||||
|
@ -183,16 +183,21 @@ public class MetadataTools {
|
|||
class_mapping.addAttribute("catalog", auditTableData.getCatalog());
|
||||
}
|
||||
|
||||
if (isAbstract != null) {
|
||||
class_mapping.addAttribute("abstract", isAbstract.toString());
|
||||
}
|
||||
|
||||
return class_mapping;
|
||||
}
|
||||
|
||||
public static Element createEntity(Document document, AuditTableData auditTableData, String discriminatorValue) {
|
||||
return createEntityCommon(document, "class", auditTableData, discriminatorValue);
|
||||
public static Element createEntity(Document document, AuditTableData auditTableData, String discriminatorValue,
|
||||
Boolean isAbstract) {
|
||||
return createEntityCommon(document, "class", auditTableData, discriminatorValue, isAbstract);
|
||||
}
|
||||
|
||||
public static Element createSubclassEntity(Document document, String subclassType, AuditTableData auditTableData,
|
||||
String extendsEntityName, String discriminatorValue) {
|
||||
Element class_mapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue);
|
||||
String extendsEntityName, String discriminatorValue, Boolean isAbstract) {
|
||||
Element class_mapping = createEntityCommon(document, subclassType, auditTableData, discriminatorValue, isAbstract);
|
||||
|
||||
class_mapping.addAttribute("extends", extendsEntityName);
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.hibernate.envers.test.integration.inheritance.tableperclass.abstractparent;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
@Audited
|
||||
public abstract class AbstractEntity {
|
||||
@Id
|
||||
public Long id;
|
||||
|
||||
@Column
|
||||
public String commonField;
|
||||
|
||||
public AbstractEntity() {
|
||||
}
|
||||
|
||||
protected AbstractEntity(Long id, String commonField) {
|
||||
this.commonField = commonField;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.hibernate.envers.test.integration.inheritance.tableperclass.abstractparent;
|
||||
|
||||
import java.util.Iterator;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-5910")
|
||||
public class AuditedAbstractParentTest extends BaseEnversJPAFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { AbstractEntity.class, EffectiveEntity1.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() {
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
// Revision 1
|
||||
em.getTransaction().begin();
|
||||
EffectiveEntity1 entity = new EffectiveEntity1( 1L, "commonField", "specificField1" );
|
||||
em.persist( entity );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbstractTableExistence() {
|
||||
Iterator<Table> tableIterator = getCfg().getTableMappings();
|
||||
while ( tableIterator.hasNext() ) {
|
||||
Table table = tableIterator.next();
|
||||
if ( "AbstractEntity_AUD".equals( table.getName() ) ) {
|
||||
Assert.assertFalse( table.isPhysicalTable() );
|
||||
return;
|
||||
}
|
||||
}
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.hibernate.envers.test.integration.inheritance.tableperclass.abstractparent;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ENTITY_1")
|
||||
@Audited
|
||||
public class EffectiveEntity1 extends AbstractEntity {
|
||||
@Column
|
||||
public String specificField1;
|
||||
|
||||
public EffectiveEntity1() {
|
||||
}
|
||||
|
||||
public EffectiveEntity1(Long id, String commonField, String specificField1) {
|
||||
super( id, commonField );
|
||||
this.specificField1 = specificField1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue