|
36 | 36 | import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl;
|
37 | 37 | import org.hibernate.metamodel.model.domain.internal.PluralAttributeBuilder;
|
38 | 38 | import org.hibernate.metamodel.model.domain.internal.SingularAttributeImpl;
|
| 39 | +import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor.InFlightAccess; |
39 | 40 | import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
40 | 41 | import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
41 | 42 | import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
|
46 | 47 | import org.hibernate.property.access.spi.Getter;
|
47 | 48 | import org.hibernate.tuple.entity.EntityMetamodel;
|
48 | 49 | import org.hibernate.type.ComponentType;
|
| 50 | +import org.hibernate.type.CompositeType; |
49 | 51 | import org.hibernate.type.EmbeddedComponentType;
|
50 | 52 | import org.hibernate.type.EntityType;
|
51 | 53 |
|
@@ -95,11 +97,45 @@ public <X, Y> PersistentAttributeDescriptor<X, Y> buildAttribute(ManagedTypeDesc
|
95 | 97 | return buildPluralAttribute( (PluralAttributeMetadata) attributeMetadata );
|
96 | 98 | }
|
97 | 99 | final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>) attributeMetadata;
|
98 |
| - final SimpleTypeDescriptor<Y> metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext() ); |
| 100 | + SimpleTypeDescriptor<Y> metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext() ); |
| 101 | + Attribute.PersistentAttributeType jpaAttributeNature = attributeMetadata.getJpaAttributeNature(); |
| 102 | + |
| 103 | + if ( attributeContext.getPropertyMapping().getType().isComponentType() && jpaAttributeNature.equals( Attribute.PersistentAttributeType.BASIC ) ) { |
| 104 | + CompositeType compositeType = (CompositeType) attributeContext.getPropertyMapping().getType(); |
| 105 | + EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<>( |
| 106 | + attributeMetadata.getJavaType(), |
| 107 | + ownerType, |
| 108 | + compositeType, |
| 109 | + context.getSessionFactory() |
| 110 | + ); |
| 111 | + context.registerEmbeddedableType(embeddableType); |
| 112 | + |
| 113 | + String[] propertyNames = compositeType.getPropertyNames(); |
| 114 | + org.hibernate.type.Type[] subtypes = compositeType.getSubtypes(); |
| 115 | + InFlightAccess<?> inFlightAccess = embeddableType.getInFlightAccess(); |
| 116 | + |
| 117 | + for ( int i = 0; i < propertyNames.length; i++ ) { |
| 118 | + SingularAttributeImpl nestedAttribute = new SingularAttributeImpl( |
| 119 | + embeddableType, |
| 120 | + propertyNames[i], |
| 121 | + Attribute.PersistentAttributeType.BASIC, |
| 122 | + new BasicTypeImpl<Object>(subtypes[i].getReturnedClass(), Type.PersistenceType.BASIC), |
| 123 | + null, |
| 124 | + false, |
| 125 | + false, |
| 126 | + property.isOptional() |
| 127 | + ); |
| 128 | + inFlightAccess.addAttribute(nestedAttribute); |
| 129 | + } |
| 130 | + |
| 131 | + metaModelType = embeddableType; |
| 132 | + jpaAttributeNature = Attribute.PersistentAttributeType.EMBEDDED; |
| 133 | + } |
| 134 | + |
99 | 135 | return new SingularAttributeImpl(
|
100 | 136 | ownerType,
|
101 | 137 | attributeMetadata.getName(),
|
102 |
| - attributeMetadata.getJpaAttributeNature(), |
| 138 | + jpaAttributeNature, |
103 | 139 | metaModelType,
|
104 | 140 | attributeMetadata.getMember(),
|
105 | 141 | false,
|
@@ -230,7 +266,7 @@ private <Y> SimpleTypeDescriptor<Y> determineSimpleType(ValueContext typeContext
|
230 | 266 | );
|
231 | 267 | context.registerEmbeddedableType( embeddableType );
|
232 | 268 |
|
233 |
| - final ManagedTypeDescriptor.InFlightAccess<Y> inFlightAccess = embeddableType.getInFlightAccess(); |
| 269 | + final InFlightAccess<Y> inFlightAccess = embeddableType.getInFlightAccess(); |
234 | 270 | final Iterator<Property> subProperties = component.getPropertyIterator();
|
235 | 271 | while ( subProperties.hasNext() ) {
|
236 | 272 | final Property property = subProperties.next();
|
@@ -954,7 +990,7 @@ public Member resolveMember(AttributeContext attributeContext) {
|
954 | 990 | final EmbeddedTypeDescriptor embeddableType = (EmbeddedTypeDescriptor<?>) attributeContext.getOwnerType();
|
955 | 991 | final String attributeName = attributeContext.getPropertyMapping().getName();
|
956 | 992 |
|
957 |
| - final Getter getter = embeddableType.getHibernateType() |
| 993 | + final Getter getter = ( ( ComponentType ) embeddableType.getHibernateType() ) |
958 | 994 | .getComponentTuplizer()
|
959 | 995 | .getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) );
|
960 | 996 | return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
|
|
0 commit comments