HHH-18394 - Fix transformation of nested subclass mappings
This commit is contained in:
parent
cb538f9d28
commit
5c993efde3
|
@ -521,7 +521,7 @@ public class HbmXmlTransformer {
|
||||||
|
|
||||||
if ( !hbmSubclass.getSubclass().isEmpty() ) {
|
if ( !hbmSubclass.getSubclass().isEmpty() ) {
|
||||||
for ( JaxbHbmDiscriminatorSubclassEntityType nestedHbmSubclass : hbmSubclass.getSubclass() ) {
|
for ( JaxbHbmDiscriminatorSubclassEntityType nestedHbmSubclass : hbmSubclass.getSubclass() ) {
|
||||||
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( hbmSubclass, hbmXmlBinding.getRoot() );
|
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( nestedHbmSubclass, hbmXmlBinding.getRoot() );
|
||||||
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
||||||
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
||||||
transferDiscriminatorSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
transferDiscriminatorSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
||||||
|
@ -561,7 +561,7 @@ public class HbmXmlTransformer {
|
||||||
|
|
||||||
if ( !hbmSubclass.getJoinedSubclass().isEmpty() ) {
|
if ( !hbmSubclass.getJoinedSubclass().isEmpty() ) {
|
||||||
for ( JaxbHbmJoinedSubclassEntityType nestedHbmSubclass : hbmSubclass.getJoinedSubclass() ) {
|
for ( JaxbHbmJoinedSubclassEntityType nestedHbmSubclass : hbmSubclass.getJoinedSubclass() ) {
|
||||||
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( hbmSubclass, hbmXmlBinding.getRoot() );
|
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( nestedHbmSubclass, hbmXmlBinding.getRoot() );
|
||||||
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
||||||
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
||||||
transferJoinedSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
transferJoinedSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
||||||
|
@ -583,7 +583,7 @@ public class HbmXmlTransformer {
|
||||||
|
|
||||||
if ( !hbmSubclass.getUnionSubclass().isEmpty() ) {
|
if ( !hbmSubclass.getUnionSubclass().isEmpty() ) {
|
||||||
for ( JaxbHbmUnionSubclassEntityType nestedHbmSubclass : hbmSubclass.getUnionSubclass() ) {
|
for ( JaxbHbmUnionSubclassEntityType nestedHbmSubclass : hbmSubclass.getUnionSubclass() ) {
|
||||||
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( hbmSubclass, hbmXmlBinding.getRoot() );
|
final String nestedSubclassEntityName = TransformationHelper.determineEntityName( nestedHbmSubclass, hbmXmlBinding.getRoot() );
|
||||||
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
final JaxbEntityImpl nestedSubclassSubclassEntity = transformationState.getMappingEntityByName().get( nestedSubclassEntityName );
|
||||||
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
final EntityTypeInfo nestedSubclassInfo = transformationState.getEntityInfoByName().get( nestedSubclassEntityName );
|
||||||
transferUnionSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
transferUnionSubclass( nestedHbmSubclass, nestedSubclassSubclassEntity, nestedSubclassInfo );
|
||||||
|
@ -1357,8 +1357,18 @@ public class HbmXmlTransformer {
|
||||||
EntityInfo hbmEntity,
|
EntityInfo hbmEntity,
|
||||||
JaxbEntityImpl mappingEntity,
|
JaxbEntityImpl mappingEntity,
|
||||||
EntityTypeInfo entityTypeInfo) {
|
EntityTypeInfo entityTypeInfo) {
|
||||||
mappingEntity.setAttributes( new JaxbAttributesContainerImpl() );
|
try {
|
||||||
transferBaseAttributes( entityTypeInfo.getPersistentClass().getEntityName(), hbmEntity.getAttributes(), entityTypeInfo, mappingEntity.getAttributes() );
|
mappingEntity.setAttributes( new JaxbAttributesContainerImpl() );
|
||||||
|
transferBaseAttributes(
|
||||||
|
entityTypeInfo.getPersistentClass().getEntityName(),
|
||||||
|
hbmEntity.getAttributes(),
|
||||||
|
entityTypeInfo,
|
||||||
|
mappingEntity.getAttributes()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error processing entity attributes : " + entityTypeInfo.getPersistentClass().getEntityName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transferBaseAttributes(
|
private void transferBaseAttributes(
|
||||||
|
@ -1368,14 +1378,28 @@ public class HbmXmlTransformer {
|
||||||
JaxbAttributesContainer attributes) {
|
JaxbAttributesContainer attributes) {
|
||||||
for ( Object hbmAttributeMapping : hbmAttributeMappings ) {
|
for ( Object hbmAttributeMapping : hbmAttributeMappings ) {
|
||||||
if ( hbmAttributeMapping instanceof JaxbHbmBasicAttributeType basic ) {
|
if ( hbmAttributeMapping instanceof JaxbHbmBasicAttributeType basic ) {
|
||||||
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( basic.getName() );
|
try {
|
||||||
attributes.getBasicAttributes().add( transformBasicAttribute( basic, propertyInfo ) );
|
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( basic.getName() );
|
||||||
|
attributes.getBasicAttributes().add( transformBasicAttribute( basic, propertyInfo ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming <property/> : " + basic.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof JaxbHbmCompositeAttributeType hbmComponent ) {
|
else if ( hbmAttributeMapping instanceof JaxbHbmCompositeAttributeType hbmComponent ) {
|
||||||
final String componentRole = roleBase + "." + hbmComponent.getName();
|
try {
|
||||||
final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole );
|
final String componentRole = roleBase + "." + hbmComponent.getName();
|
||||||
final JaxbEmbeddableImpl jaxbEmbeddable = applyEmbeddable( roleBase, hbmComponent, componentTypeInfo );
|
final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole );
|
||||||
attributes.getEmbeddedAttributes().add( transformEmbedded( jaxbEmbeddable, hbmComponent ) );
|
final JaxbEmbeddableImpl jaxbEmbeddable = applyEmbeddable(
|
||||||
|
roleBase,
|
||||||
|
hbmComponent,
|
||||||
|
componentTypeInfo
|
||||||
|
);
|
||||||
|
attributes.getEmbeddedAttributes().add( transformEmbedded( jaxbEmbeddable, hbmComponent ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming <component/> : " + hbmComponent.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof JaxbHbmPropertiesType hbmProperties ) {
|
else if ( hbmAttributeMapping instanceof JaxbHbmPropertiesType hbmProperties ) {
|
||||||
// while we could simply "unwrap" the <properties/> itself and inline the attributes,
|
// while we could simply "unwrap" the <properties/> itself and inline the attributes,
|
||||||
|
@ -1398,30 +1422,64 @@ public class HbmXmlTransformer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof JaxbHbmOneToOneType hbmOneToOne ) {
|
else if ( hbmAttributeMapping instanceof JaxbHbmOneToOneType hbmOneToOne ) {
|
||||||
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmOneToOne.getName() );
|
try {
|
||||||
transferOneToOne( hbmOneToOne, propertyInfo, attributes );
|
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmOneToOne.getName() );
|
||||||
|
transferOneToOne( hbmOneToOne, propertyInfo, attributes );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming <one-to-one/> : " + hbmOneToOne.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof JaxbHbmManyToOneType hbmManyToOne ) {
|
else if ( hbmAttributeMapping instanceof JaxbHbmManyToOneType hbmManyToOne ) {
|
||||||
transferManyToOne( managedTypeInfo, attributes, hbmManyToOne );
|
try {
|
||||||
|
transferManyToOne( managedTypeInfo, attributes, hbmManyToOne );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming <many-to-one/> : " + hbmManyToOne.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType any ) {
|
else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType any ) {
|
||||||
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( any.getName() );
|
try {
|
||||||
attributes.getAnyMappingAttributes().add( transformAnyAttribute( any, propertyInfo ) );
|
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( any.getName() );
|
||||||
|
attributes.getAnyMappingAttributes().add( transformAnyAttribute( any, propertyInfo ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming <any/> : " + any.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmAttributeMapping instanceof PluralAttributeInfo hbmCollection ) {
|
else if ( hbmAttributeMapping instanceof PluralAttributeInfo hbmCollection ) {
|
||||||
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmCollection.getName() );
|
final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmCollection.getName() );
|
||||||
if ( hbmCollection.getElement() != null || hbmCollection.getCompositeElement() != null ) {
|
if ( hbmCollection.getElement() != null || hbmCollection.getCompositeElement() != null ) {
|
||||||
attributes.getElementCollectionAttributes().add( transformElementCollection( roleBase, hbmCollection, propertyInfo ) );
|
try {
|
||||||
|
attributes.getElementCollectionAttributes().add( transformElementCollection( roleBase, hbmCollection, propertyInfo ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming element-collection : " + hbmCollection.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmCollection.getOneToMany() != null ) {
|
else if ( hbmCollection.getOneToMany() != null ) {
|
||||||
attributes.getOneToManyAttributes().add( transformOneToMany( hbmCollection, propertyInfo ) );
|
try {
|
||||||
|
attributes.getOneToManyAttributes().add( transformOneToMany( hbmCollection, propertyInfo ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming one-to-many : " + hbmCollection.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmCollection.getManyToMany() != null ) {
|
else if ( hbmCollection.getManyToMany() != null ) {
|
||||||
attributes.getManyToManyAttributes().add( transformManyToMany( hbmCollection, propertyInfo ) );
|
try {
|
||||||
|
attributes.getManyToManyAttributes().add( transformManyToMany( hbmCollection, propertyInfo ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming many-to-many : " + hbmCollection.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( hbmCollection.getManyToAny() != null ) {
|
else if ( hbmCollection.getManyToAny() != null ) {
|
||||||
attributes.getPluralAnyMappingAttributes().add( transformPluralAny( hbmCollection ) );
|
try {
|
||||||
|
attributes.getPluralAnyMappingAttributes().add( transformPluralAny( hbmCollection ) );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new TransformationException( "Error transforming many-to-any : " + hbmCollection.getName(), e, origin() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException( "Unexpected node type - " + hbmCollection );
|
throw new UnsupportedOperationException( "Unexpected node type - " + hbmCollection );
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
|
||||||
|
*/
|
||||||
|
package org.hibernate.boot.jaxb.hbm.transform;
|
||||||
|
|
||||||
|
import org.hibernate.boot.MappingException;
|
||||||
|
import org.hibernate.boot.jaxb.Origin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generalized error while performing {@code hbm.xml} transformation
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class TransformationException extends MappingException {
|
||||||
|
public TransformationException(String message, Origin origin) {
|
||||||
|
super( message, origin );
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransformationException(String message, Throwable root, Origin origin) {
|
||||||
|
super( message, root, origin );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue