From 520c8f200486d3b3efe71510fe0bf1abf61e1a8e Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 23 Oct 2019 16:15:56 +0100 Subject: [PATCH] initial work for table per class inheritance --- .../entity/AbstractEntityPersister.java | 10 +++++-- .../entity/UnionSubclassEntityPersister.java | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index a35e34711d..a2693087cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -6070,7 +6070,7 @@ public abstract class AbstractEntityPersister return; } - if ( superMappingType != null ) { + if ( superMappingType != null && shouldProcessSuperMapping() ) { ( (InFlightEntityMappingType) superMappingType ).prepareMappingModel( creationProcess ); this.identifierMapping = superMappingType.getIdentifierMapping(); @@ -6097,7 +6097,7 @@ public abstract class AbstractEntityPersister ); } - if ( getDiscriminatorType() == null ) { + if ( getDiscriminatorType() == null && shouldProcessSuperMapping() ) { discriminatorMapping = null; } else { @@ -6127,7 +6127,7 @@ public abstract class AbstractEntityPersister final NonIdentifierAttribute runtimeAttrDefinition = currentEntityMetamodel.getProperties()[i]; final Property bootProperty = bootEntityDescriptor.getProperty( runtimeAttrDefinition.getName() ); - if ( superMappingType != null && superMappingType.findAttributeMapping( bootProperty.getName() ) != null ) { + if ( superMappingType != null && superMappingType.findAttributeMapping( bootProperty.getName() ) != null && shouldProcessSuperMapping() ) { // its defined on the super-type, skip it here } else { @@ -6156,6 +6156,10 @@ public abstract class AbstractEntityPersister } } + protected boolean shouldProcessSuperMapping(){ + return true; + } + @Override public void linkWithSuperType(MappingModelCreationProcess creationProcess) { if ( getMappedSuperclass() == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 7a7702f09c..d2243fa4d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -14,6 +14,8 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Supplier; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; @@ -21,6 +23,7 @@ import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.boot.model.relational.Database; +import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.cfg.Settings; @@ -37,11 +40,27 @@ import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.SingletonIterator; import org.hibernate.mapping.Column; import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Table; +import org.hibernate.metamodel.mapping.EntityIdentifierMapping; +import org.hibernate.metamodel.mapping.internal.EntityDiscriminatorMappingImpl; +import org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType; +import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.persister.spi.PersisterCreationContext; +import org.hibernate.query.NavigablePath; +import org.hibernate.query.sqm.sql.SqlExpressionResolver; import org.hibernate.sql.SelectFragment; import org.hibernate.sql.SimpleSelect; +import org.hibernate.sql.ast.JoinType; +import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; +import org.hibernate.sql.ast.spi.SqlAstCreationContext; +import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.sql.ast.tree.predicate.Predicate; +import org.hibernate.tuple.NonIdentifierAttribute; +import org.hibernate.tuple.entity.EntityMetamodel; +import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -220,6 +239,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { return subclassSpaces; } + @Override + public String getRootTableName() { + return tableName; + } + public String getTableName() { return subquery; } @@ -285,6 +309,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { return select.addCondition( getIdentifierColumnNames(), "=?" ).toStatementString(); } + @Override + protected boolean shouldProcessSuperMapping() { + return false; + } + protected String getDiscriminatorFormula() { return null; }