Skip to content

Commit 47a7a07

Browse files
committed
initial work for table per class inheritance
1 parent 2ea03f7 commit 47a7a07

File tree

5 files changed

+485
-68
lines changed

5 files changed

+485
-68
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,8 +5482,6 @@ public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SharedSes
54825482
return accessOptimizer.getPropertyValues( entity );
54835483
}
54845484

5485-
final Collection<AttributeMapping> attributeMappings = getAttributeMappings();
5486-
54875485
final Object[] result = new Object[this.attributeMappings.size()];
54885486
for ( int i = 0; i < this.attributeMappings.size(); i++ ) {
54895487
result[i] = this.attributeMappings.get( i ).getPropertyAccess().getGetter().getForInsert(
@@ -6102,7 +6100,7 @@ public CacheEntry buildCacheEntry(Object entity, Object[] state, Object version,
61026100
private List<AttributeMapping> attributeMappings;
61036101
private List<Fetchable> staticFetchableList;
61046102

6105-
private ReflectionOptimizer.AccessOptimizer accessOptimizer;
6103+
protected ReflectionOptimizer.AccessOptimizer accessOptimizer;
61066104

61076105
@Override
61086106
public void visitAttributeMappings(Consumer<AttributeMapping> action) {
@@ -6142,17 +6140,7 @@ public void prepareMappingModel(MappingModelCreationProcess creationProcess) {
61426140
);
61436141
}
61446142

6145-
if ( getDiscriminatorType() == null && shouldProcessSuperMapping() ) {
6146-
discriminatorMapping = null;
6147-
}
6148-
else {
6149-
discriminatorMapping = new EntityDiscriminatorMappingImpl(
6150-
this,
6151-
getRootTableName(),
6152-
getDiscriminatorColumnName(),
6153-
(BasicType) getDiscriminatorType()
6154-
);
6155-
}
6143+
buildDiscriminatorMapping();
61566144

61576145
// todo (6.0) : support for natural-id not yet implemented
61586146
naturalIdMapping = null;
@@ -6165,14 +6153,13 @@ public void prepareMappingModel(MappingModelCreationProcess creationProcess) {
61656153
.getEntityBinding( getEntityName() );
61666154

61676155
final EntityMetamodel currentEntityMetamodel = this.getEntityMetamodel();
6168-
6169-
int stateArrayPosition = superMappingType == null ? 0 : superMappingType.getNumberOfAttributeMappings();
6156+
int stateArrayPosition = getStateArrayInitialPosition( creationProcess );
61706157

61716158
for ( int i = 0; i < currentEntityMetamodel.getPropertySpan(); i++ ) {
61726159
final NonIdentifierAttribute runtimeAttrDefinition = currentEntityMetamodel.getProperties()[i];
61736160
final Property bootProperty = bootEntityDescriptor.getProperty( runtimeAttrDefinition.getName() );
61746161

6175-
if ( superMappingType != null && superMappingType.findAttributeMapping( bootProperty.getName() ) != null && shouldProcessSuperMapping() ) {
6162+
if ( superMappingType != null && superMappingType.findAttributeMapping( bootProperty.getName() ) != null ) {
61766163
// its defined on the super-type, skip it here
61776164
}
61786165
else {
@@ -6201,6 +6188,33 @@ public void prepareMappingModel(MappingModelCreationProcess creationProcess) {
62016188
}
62026189
}
62036190

6191+
protected int getStateArrayInitialPosition(MappingModelCreationProcess creationProcess) {
6192+
// todo (6.0) not sure this is correct in case of SingleTable Inheritance and for Table per class when the selection is the root
6193+
int stateArrayPosition;
6194+
if ( superMappingType != null ) {
6195+
( (InFlightEntityMappingType) superMappingType ).prepareMappingModel( creationProcess );
6196+
stateArrayPosition = superMappingType.getNumberOfAttributeMappings();
6197+
}
6198+
else {
6199+
stateArrayPosition = 0;
6200+
}
6201+
return stateArrayPosition;
6202+
}
6203+
6204+
protected void buildDiscriminatorMapping() {
6205+
if ( getDiscriminatorType() == null) {
6206+
discriminatorMapping = null;
6207+
}
6208+
else {
6209+
discriminatorMapping = new EntityDiscriminatorMappingImpl(
6210+
this,
6211+
getRootTableName(),
6212+
getDiscriminatorColumnName(),
6213+
(BasicType) getDiscriminatorType()
6214+
);
6215+
}
6216+
}
6217+
62046218
protected boolean shouldProcessSuperMapping(){
62056219
return true;
62066220
}
@@ -6524,6 +6538,7 @@ public void visitFetchables(
65246538
EntityMappingType treatTargetType) {
65256539
if ( treatTargetType == null ) {
65266540
getStaticFetchableList().forEach( fetchableConsumer );
6541+
// staticFetchableList.forEach( fetchableConsumer );
65276542
// EARLY EXIT!!!
65286543
return;
65296544
}

0 commit comments

Comments
 (0)