From 288155bcb2df3791487b00f453e3195cc4330694 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 24 Jul 2012 02:30:40 -0500 Subject: [PATCH] HHH-6159 - Create EntityManagerFactoryBuilder : integrate EntityManagerFactoryBuilder with metamodel codebase --- .../internal/SessionFactoryImpl.java | 7 +- .../internal/AbstractIdentifiableType.java | 43 +++------ .../internal/AbstractManagedType.java | 1 + .../internal/UnsupportedFeature.java | 3 +- .../internal/builder/AttributeBuilder.java | 16 +--- .../internal/builder/MetamodelBuilder.java | 19 +++- .../internal/legacy/AbstractType.java | 8 +- .../internal/legacy/AttributeFactory.java | 96 +++++++++++++------ .../internal/legacy/MetadataContext.java | 25 +++++ .../java/org/hibernate/mapping/Property.java | 4 + .../spi/domain/PluralAttributeNature.java | 5 +- .../boot/spi/JpaUnifiedSettingsBuilder.java | 18 ++-- .../internal/EntityManagerFactoryImpl.java | 5 - .../internal/EntityManagerMessageLogger.java | 48 +++++----- 14 files changed, 180 insertions(+), 118 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 439484d74a..1c7271a95b 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -757,7 +757,12 @@ public final class SessionFactoryImpl // Prepare persisters and link them up with their cache // region/access-strategy - final MetamodelBuilder jpaMetamodelBuilder = new MetamodelBuilder( this ); + final MetamodelBuilder jpaMetamodelBuilder = new MetamodelBuilder( + this, + JpaMetaModelPopulationSetting.parse( + properties.getProperty( AvailableSettings.JPA_METAMODEL_POPULATION ) + ) + ); StringBuilder stringBuilder = new StringBuilder(); if ( settings.getCacheRegionPrefix() != null) { diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractIdentifiableType.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractIdentifiableType.java index 2a04634ec5..9a556857cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractIdentifiableType.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractIdentifiableType.java @@ -62,9 +62,7 @@ public abstract class AbstractIdentifiableType isVersioned = versioned; } - /** - * {@inheritDoc} - */ + @Override public AbstractIdentifiableType getSupertype() { return ( AbstractIdentifiableType ) super.getSupertype(); } @@ -87,16 +85,12 @@ public abstract class AbstractIdentifiableType return getSupertype(); } - /** - * {@inheritDoc} - */ + @Override public boolean hasSingleIdAttribute() { return hasIdentifierProperty; } - /** - * {@inheritDoc} - */ + @Override @SuppressWarnings({ "unchecked" }) public SingularAttribute getId(Class javaType) { final SingularAttribute id_; @@ -137,10 +131,7 @@ public abstract class AbstractIdentifiableType } } - - /** - * {@inheritDoc} - */ + @Override @SuppressWarnings({ "unchecked" }) public SingularAttribute getDeclaredId(Class javaType) { checkDeclaredId(); @@ -161,9 +152,7 @@ public abstract class AbstractIdentifiableType } } - /** - * {@inheritDoc} - */ + @Override public Type getIdType() { if ( id != null ) { checkSimpleId(); @@ -179,9 +168,7 @@ public abstract class AbstractIdentifiableType ( getSupertype() != null && getSupertype().hasIdClassAttributesDefined() ); } - /** - * {@inheritDoc} - */ + @Override public Set> getIdClassAttributes() { if ( idClassAttributes != null ) { checkIdClass(); @@ -215,9 +202,7 @@ public abstract class AbstractIdentifiableType } } - /** - * {@inheritDoc} - */ + @Override public boolean hasVersionAttribute() { return isVersioned; } @@ -226,9 +211,7 @@ public abstract class AbstractIdentifiableType return isVersioned && version != null; } - /** - * {@inheritDoc} - */ + @Override @SuppressWarnings({ "unchecked" }) public SingularAttribute getVersion(Class javaType) { if ( ! hasVersionAttribute() ) { @@ -247,9 +230,7 @@ public abstract class AbstractIdentifiableType return version_; } - /** - * {@inheritDoc} - */ + @Override @SuppressWarnings({ "unchecked" }) public SingularAttribute getDeclaredVersion(Class javaType) { checkDeclaredVersion(); @@ -279,14 +260,17 @@ public abstract class AbstractIdentifiableType } } + @Override public Builder getBuilder() { final AbstractManagedType.Builder managedBuilder = super.getBuilder(); return new Builder() { + @Override public void applyIdAttribute(SingularAttributeImpl idAttribute) { AbstractIdentifiableType.this.id = idAttribute; managedBuilder.addAttribute( idAttribute ); } + @Override public void applyIdClassAttributes(Set> idClassAttributes) { for ( SingularAttribute idClassAttribute : idClassAttributes ) { if ( AbstractIdentifiableType.this == idClassAttribute.getDeclaringType() ) { @@ -297,12 +281,13 @@ public abstract class AbstractIdentifiableType } AbstractIdentifiableType.this.idClassAttributes = idClassAttributes; } - + @Override public void applyVersionAttribute(SingularAttributeImpl versionAttribute) { AbstractIdentifiableType.this.version = versionAttribute; managedBuilder.addAttribute( versionAttribute ); } + @Override public void addAttribute(Attribute attribute) { managedBuilder.addAttribute( attribute ); } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractManagedType.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractManagedType.java index 7634bc5d3b..19f0996fe4 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/AbstractManagedType.java @@ -74,6 +74,7 @@ public abstract class AbstractManagedType throw new IllegalStateException( "Type has been locked" ); } return new Builder() { + @Override public void addAttribute(Attribute attribute) { declaredAttributes.put( attribute.getName(), attribute ); final Bindable.BindableType bindableType = ( ( Bindable ) attribute ).getBindableType(); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/UnsupportedFeature.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/UnsupportedFeature.java index 176c47f580..65ce3dec77 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/UnsupportedFeature.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/UnsupportedFeature.java @@ -30,7 +30,8 @@ package org.hibernate.jpa.metamodel.internal; * @author Steve Ebersole */ public enum UnsupportedFeature { - ANY( "ANY mappings not supported in JPA metamodel" ); + ANY( "ANY mappings not supported in JPA metamodel" ), + ARRAY( "Arrays (HBM mappings) are not supported in JPA metamodel" ); private final String message; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java index 4b896262b9..1899f2ee8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java @@ -321,6 +321,10 @@ public class AttributeBuilder { else { final PluralAttributeBinding pluralAttributeBinding = (PluralAttributeBinding) attributeBinding; + if ( pluralAttributeBinding.getAttribute().getNature() == PluralAttributeNature.ARRAY ) { + context.handleUnsupportedFeature( UnsupportedFeature.ARRAY ); + } + // First, determine the type of the elements and use that to help determine the // collection type) final PluralAttributeElementBinding elementBinding = pluralAttributeBinding.getPluralAttributeElementBinding(); @@ -370,18 +374,6 @@ public class AttributeBuilder { keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC; } } - else { - // for the sake of symmetry... - if ( pluralAttributeBinding.getPluralAttributeKeyBinding() != null ) { - throw new HibernateException( - String.format( - "Encountered non-Map attribute binding with associated map-key binding : %s#%s", - jpaOwner.getJavaType().getName(), - pluralAttributeBinding.getAttribute().getName() - ) - ); - } - } return new PluralAttributeMetadataImpl( pluralAttributeBinding, diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java index da6a25a3de..b2424f89e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/MetamodelBuilder.java @@ -42,6 +42,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.metamodel.internal.AbstractIdentifiableType; import org.hibernate.jpa.metamodel.internal.EmbeddableTypeImpl; import org.hibernate.jpa.metamodel.internal.EntityTypeImpl; +import org.hibernate.jpa.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.jpa.metamodel.internal.MappedSuperclassTypeImpl; import org.hibernate.jpa.metamodel.internal.MetamodelImpl; import org.hibernate.jpa.metamodel.internal.UnsupportedFeature; @@ -82,6 +83,7 @@ public class MetamodelBuilder { private final Map, MappedSuperclassTypeImpl> mappedSuperclassTypeMap = new HashMap, MappedSuperclassTypeImpl>(); // these fields are needed just for the duration of building the metamodel + private final JpaMetaModelPopulationSetting populationSetting; private final AttributeBuilder attributeBuilder; private final Map entityTypeByNameMap = new HashMap(); private final Map mappedSuperclassEntityNameMap = new HashMap(); @@ -89,8 +91,9 @@ public class MetamodelBuilder { private Set alreadyProcessed = new HashSet(); - public MetamodelBuilder(SessionFactoryImplementor sessionFactory) { + public MetamodelBuilder(SessionFactoryImplementor sessionFactory, JpaMetaModelPopulationSetting populationSetting) { this.sessionFactory = sessionFactory; + this.populationSetting = populationSetting; this.attributeBuilder = new AttributeBuilder( new AttributeBuilderContext() ); } @@ -328,10 +331,18 @@ public class MetamodelBuilder { } private void populateStaticMetamodel(AbstractIdentifiableType jpaDescriptor) { + if ( populationSetting == JpaMetaModelPopulationSetting.DISABLED ) { + return; + } + // todo : implement ! } private void populateStaticMetamodel(EmbeddableTypeImpl embeddable) { + if ( populationSetting == JpaMetaModelPopulationSetting.DISABLED ) { + return; + } + // todo : implement ! } @@ -340,6 +351,9 @@ public class MetamodelBuilder { * Implementation of AttributeBuilder.Context */ class AttributeBuilderContext implements AttributeBuilder.Context { + public AttributeBuilderContext() { + } + public Type locateEntityTypeByName(String entityName) { return entityTypeByNameMap.get( entityName ); } @@ -379,8 +393,7 @@ public class MetamodelBuilder { @Override public void handleUnsupportedFeature(UnsupportedFeature feature) { - boolean ignoreUnsupported = true; - if ( ignoreUnsupported ) { + if ( populationSetting == JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED ) { log.debug( "Ignoring mapping construct not supported as part of JPA metamodel [" + feature.getMessage() + "]" ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AbstractType.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AbstractType.java index 6ddf2500f8..726dd8e57a 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AbstractType.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AbstractType.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AttributeFactory.java index 42180d540f..10376d1ced 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/AttributeFactory.java @@ -40,11 +40,13 @@ import org.jboss.logging.Logger; import org.hibernate.annotations.common.AssertionFailure; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.mapping.Array; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; import org.hibernate.mapping.Map; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.PrimitiveArray; import org.hibernate.mapping.Property; import org.hibernate.mapping.Value; import org.hibernate.tuple.entity.EntityMetamodel; @@ -441,19 +443,17 @@ public class AttributeFactory { LOG.trace("Starting attribute metadata determination [" + attributeContext.getPropertyMapping().getName() + "]"); final Member member = memberResolver.resolveMember( attributeContext ); LOG.trace(" Determined member [" + member + "]"); + if ( member == null ) { + return null; + } final Value value = attributeContext.getPropertyMapping().getValue(); final org.hibernate.type.Type type = value.getType(); LOG.trace(" Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]"); if ( type.isAnyType() ) { - // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589 - if ( context.isIgnoreUnsupported() ) { - return null; - } - else { - throw new UnsupportedOperationException( "ANY not supported" ); - } + context.handleAnyMapping(); + return null; } else if ( type.isAssociationType() ) { // collection or entity @@ -466,8 +466,15 @@ public class AttributeFactory { determineSingularAssociationAttributeType( member ) ); } + // collection if (value instanceof Collection) { + if ( Array.class.isInstance( value ) + || PrimitiveArray.class.isInstance( value ) ) { + context.handleArrayMapping(); + return null; + } + final Collection collValue = (Collection)value; final Value elementValue = collValue.getElement(); final org.hibernate.type.Type elementType = elementValue.getType(); @@ -476,8 +483,9 @@ public class AttributeFactory { // collection type) final Attribute.PersistentAttributeType elementPersistentAttributeType; final Attribute.PersistentAttributeType persistentAttributeType; - if (elementType.isAnyType()) { - throw new UnsupportedOperationException("collection of any not supported yet"); + if ( elementType.isAnyType() ) { + context.handleAnyMapping(); + return null; } final boolean isManyToMany = isManyToMany(member); if (elementValue instanceof Component) { @@ -498,15 +506,33 @@ public class AttributeFactory { final Value keyValue = ((Map)value).getIndex(); final org.hibernate.type.Type keyType = keyValue.getType(); - if (keyType.isAnyType()) throw new UnsupportedOperationException("collection of any not supported yet"); - if (keyValue instanceof Component) keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED; - else if (keyType.isAssociationType()) keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE; - else keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC; - } else keyPersistentAttributeType = null; - return new PluralAttributeMetadataImpl(attributeContext.getPropertyMapping(), attributeContext.getOwnerType(), - member, persistentAttributeType, elementPersistentAttributeType, - keyPersistentAttributeType); - } else if (value instanceof OneToMany) { + if ( keyType.isAnyType() ) { + context.handleAnyMapping(); + return null; + } + if (keyValue instanceof Component) { + keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED; + } + else if (keyType.isAssociationType()) { + keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE; + } + else { + keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC; + } + } + else { + keyPersistentAttributeType = null; + } + return new PluralAttributeMetadataImpl( + attributeContext.getPropertyMapping(), + attributeContext.getOwnerType(), + member, + persistentAttributeType, + elementPersistentAttributeType, + keyPersistentAttributeType + ); + } + else if (value instanceof OneToMany) { // TODO : is this even possible??? Really OneToMany should be describing the // element value within a o.h.mapping.Collection (see logic branch above) throw new IllegalArgumentException("HUH???"); @@ -878,9 +904,7 @@ public class AttributeFactory { } private final MemberResolver EMBEDDED_MEMBER_RESOLVER = new MemberResolver() { - /** - * {@inheritDoc} - */ + @Override public Member resolveMember(AttributeContext attributeContext) { final EmbeddableTypeImpl embeddableType = ( EmbeddableTypeImpl ) attributeContext.getOwnerType(); final String attributeName = attributeContext.getPropertyMapping().getName(); @@ -893,21 +917,23 @@ public class AttributeFactory { private final MemberResolver VIRTUAL_IDENTIFIER_MEMBER_RESOLVER = new MemberResolver() { - /** - * {@inheritDoc} - */ + @Override public Member resolveMember(AttributeContext attributeContext) { final IdentifiableType identifiableType = (IdentifiableType) attributeContext.getOwnerType(); final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType ); + if ( entityMetamodel == null ) { + // this happens with badly written custom persisters, like the ones in our test suite :) + return null; + } if ( ! entityMetamodel.getIdentifierProperty().isVirtual() ) { throw new IllegalArgumentException( "expecting IdClass mapping" ); } org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType(); - if ( ! EmbeddedComponentType.class.isInstance( type ) ) { + if ( ! ComponentType.class.isInstance( type ) ) { throw new IllegalArgumentException( "expecting IdClass mapping" ); } - final EmbeddedComponentType componentType = (EmbeddedComponentType) type; + final ComponentType componentType = (ComponentType) type; final String attributeName = attributeContext.getPropertyMapping().getName(); return componentType.getComponentTuplizer() .getGetter( componentType.getPropertyIndex( attributeName ) ) @@ -919,9 +945,7 @@ public class AttributeFactory { * A {@link java.lang.reflect.Member} resolver for normal attributes. */ private final MemberResolver NORMAL_MEMBER_RESOLVER = new MemberResolver() { - /** - * {@inheritDoc} - */ + @Override public Member resolveMember(AttributeContext attributeContext) { final AbstractManagedType ownerType = attributeContext.getOwnerType(); final Property property = attributeContext.getPropertyMapping(); @@ -933,6 +957,10 @@ public class AttributeFactory { || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) { final IdentifiableType identifiableType = (IdentifiableType) ownerType; final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType ); + if ( entityMetamodel == null ) { + // this happens with badly written custom persisters, like the ones in our test suite :) + return null; + } final String propertyName = property.getName(); final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName ); if ( index == null ) { @@ -952,9 +980,14 @@ public class AttributeFactory { }; private final MemberResolver IDENTIFIER_MEMBER_RESOLVER = new MemberResolver() { + @Override public Member resolveMember(AttributeContext attributeContext) { final IdentifiableType identifiableType = (IdentifiableType) attributeContext.getOwnerType(); final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType ); + if ( entityMetamodel == null ) { + // this happens with badly written custom persisters, like the ones in our test suite :) + return null; + } if ( ! attributeContext.getPropertyMapping().getName() .equals( entityMetamodel.getIdentifierProperty().getName() ) ) { // this *should* indicate processing part of an IdClass... @@ -965,9 +998,14 @@ public class AttributeFactory { }; private final MemberResolver VERSION_MEMBER_RESOLVER = new MemberResolver() { + @Override public Member resolveMember(AttributeContext attributeContext) { final IdentifiableType identifiableType = (IdentifiableType) attributeContext.getOwnerType(); final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType ); + if ( entityMetamodel == null ) { + // this happens with badly written custom persisters, like the ones in our test suite :) + return null; + } final String versionPropertyName = attributeContext.getPropertyMapping().getName(); if ( ! versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) { // this should never happen, but to be safe... diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/MetadataContext.java index 63b4b6ac6c..32fbae8305 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/legacy/MetadataContext.java @@ -196,6 +196,14 @@ class MetadataContext { LOG.trace("Starting entity [" + safeMapping.getEntityName() + "]"); try { final EntityTypeImpl jpa2Mapping = entityTypesByPersistentClass.get( safeMapping ); + if ( ! safeMapping.getEntityName().equals( jpa2Mapping.getJavaType().getName() ) ) { + // skip it + continue; + } + if ( sessionFactory.getEntityPersister( safeMapping.getEntityName() ).getEntityMetamodel() == null ) { + // skip it + continue; + } applyIdMetadata( safeMapping, jpa2Mapping ); applyVersionAttribute( safeMapping, jpa2Mapping ); Iterator properties = safeMapping.getDeclaredPropertyIterator(); @@ -482,4 +490,21 @@ class MetadataContext { } return persistentClass; } + + public void handleAnyMapping() { + // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589 + if ( isIgnoreUnsupported() ) { + } + else { + throw new UnsupportedOperationException( "ANY not supported" ); + } + } + + public void handleArrayMapping() { + if ( isIgnoreUnsupported() ) { + } + else { + throw new UnsupportedOperationException( "Arrays not supported" ); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index cffdc68e2d..8b206dfc38 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -74,6 +74,10 @@ public class Property implements Serializable, MetaAttributable { * @return True if synthetic; false otherwise. */ public boolean isSynthetic() { + //noinspection SimplifiableIfStatement + if ( isComposite() ) { + return ( (Component) value ).isEmbedded(); + } return false; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttributeNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttributeNature.java index cfa2185128..cc67b18789 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttributeNature.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/PluralAttributeNature.java @@ -34,6 +34,7 @@ import java.util.Set; * @author Steve Ebersole */ public enum PluralAttributeNature { + ARRAY( "array", Object[].class ), BAG( "bag", Collection.class ), IDBAG( "idbag", Collection.class ), SET( "set", Set.class ), @@ -47,7 +48,9 @@ public enum PluralAttributeNature { PluralAttributeNature(String name, Class javaContract) { this.name = name; this.javaContract = javaContract; - this.indexed = Map.class.isAssignableFrom( javaContract ) || List.class.isAssignableFrom( javaContract ); + this.indexed = Map.class.isAssignableFrom( javaContract ) + || List.class.isAssignableFrom( javaContract ) + || javaContract.isArray(); } public String getName() { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/JpaUnifiedSettingsBuilder.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/JpaUnifiedSettingsBuilder.java index 818bb82ea1..e22eaa5341 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/JpaUnifiedSettingsBuilder.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/JpaUnifiedSettingsBuilder.java @@ -25,7 +25,6 @@ package org.hibernate.jpa.boot.spi; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -99,7 +98,7 @@ public class JpaUnifiedSettingsBuilder { } private static class ResultImpl implements Result { - private final Map settings = new ConcurrentHashMap(); + private final Map settings = new ConcurrentHashMap(); private final CfgXmlMappingArtifactsImpl cfgXmlMappingArtifacts = new CfgXmlMappingArtifactsImpl(); @Override @@ -118,8 +117,8 @@ public class JpaUnifiedSettingsBuilder { PersistenceUnitDescriptor persistenceUnit, Map integrationSettings, final BootstrapServiceRegistry bootstrapServiceRegistry) { - final Map merged = new HashMap(); // first, apply persistence.xml-defined settings + final Map merged = new HashMap(); if ( persistenceUnit.getProperties() != null ) { merged.putAll( persistenceUnit.getProperties() ); } @@ -174,12 +173,13 @@ public class JpaUnifiedSettingsBuilder { } } - // was getting NPE exceptions from the underlying map when just using #putAll, so going this safer route... - Iterator itr = merged.entrySet().iterator(); - while ( itr.hasNext() ) { - final Map.Entry entry = (Map.Entry) itr.next(); - if ( entry.getValue() == null ) { - itr.remove(); + applyAllNonNull( merged ); + } + + private void applyAllNonNull(Map values) { + for ( Map.Entry entry : values.entrySet() ) { + if ( entry.getValue() != null ) { + settings.put( entry.getKey(), entry.getValue() ); } } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java index a817a231e5..5607f4ff61 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryImpl.java @@ -41,7 +41,6 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.jboss.logging.Logger; @@ -59,15 +58,11 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.UUIDGenerator; import org.hibernate.internal.SessionFactoryImpl; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.HibernateQuery; import org.hibernate.jpa.boot.internal.SettingsImpl; import org.hibernate.jpa.criteria.CriteriaBuilderImpl; -import org.hibernate.jpa.metamodel.internal.JpaMetaModelPopulationSetting; -import org.hibernate.jpa.metamodel.internal.legacy.MetamodelImpl; import org.hibernate.jpa.internal.util.PersistenceUtilHelper; -import org.hibernate.mapping.PersistentClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.service.ServiceRegistry; diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerMessageLogger.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerMessageLogger.java index 099ae9bcd1..3d3dd9d2a1 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerMessageLogger.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerMessageLogger.java @@ -70,19 +70,19 @@ public interface EntityManagerMessageLogger extends CoreMessageLogger { @Message( value = "Exploded jar file not a directory (ignored): %s", id = 15006 ) void explodedJarNotDirectory( URL jarUrl ); - /** - * Simply deprecated for now to show the fact that id 15007 is still in use... - * - * @deprecated Moved to hibernate-core in conjunction with moving JPA metamodel generation to SessionFactory - */ - @Override - @Deprecated - @LogMessage( level = ERROR ) - @Message( value = "Illegal argument on static metamodel field injection : %s#%s; expected type : %s; encountered type : %s", id = 15007 ) - void illegalArgumentOnStaticMetamodelFieldInjection( String metamodelClassName, - String attributeName, - String attributeJavaType, - String metamodelFieldJavaType ); +// /** +// * Simply deprecated for now to show the fact that id 15007 is still in use... +// * +// * @deprecated Moved to hibernate-core in conjunction with moving JPA metamodel generation to SessionFactory +// */ +// @Override +// @Deprecated +// @LogMessage( level = ERROR ) +// @Message( value = "Illegal argument on static metamodel field injection : %s#%s; expected type : %s; encountered type : %s", id = 15007 ) +// void illegalArgumentOnStaticMetamodelFieldInjection( String metamodelClassName, +// String attributeName, +// String attributeJavaType, +// String metamodelFieldJavaType ); @LogMessage( level = ERROR ) @Message( value = "Malformed URL: %s", id = 15008 ) @@ -99,17 +99,17 @@ public interface EntityManagerMessageLogger extends CoreMessageLogger { void unableToFindFile( URL jarUrl, @Cause Exception e ); - /** - * Simply deprecated for now to show the fact that id 15011 is still in use... - * - * @deprecated Moved to hibernate-core in conjunction with moving JPA metamodel generation to SessionFactory - */ - @Override - @Deprecated - @LogMessage( level = ERROR ) - @Message( value = "Unable to locate static metamodel field : %s#%s", id = 15011 ) - void unableToLocateStaticMetamodelField( String metamodelClassName, - String attributeName ); +// /** +// * Simply deprecated for now to show the fact that id 15011 is still in use... +// * +// * @deprecated Moved to hibernate-core in conjunction with moving JPA metamodel generation to SessionFactory +// */ +// @Override +// @Deprecated +// @LogMessage( level = ERROR ) +// @Message( value = "Unable to locate static metamodel field : %s#%s", id = 15011 ) +// void unableToLocateStaticMetamodelField( String metamodelClassName, +// String attributeName ); @LogMessage( level = INFO ) @Message( value = "Using provided datasource", id = 15012 )