Search in sources :

Example 11 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class ResultSetMappingBinder method bind.

/**
	 * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements.
	 * <p/>
	 * This form is used for ResultSet mappings defined outside the context of any specific entity.
	 * For {@code hbm.xml} this means at the root of the document.  For annotations, this means at
	 * the package level.
	 *
	 * @param resultSetMappingSource The XML data as a JAXB binding
	 * @param context The mapping state
	 *
	 * @return The ResultSet mapping descriptor
	 */
public static ResultSetMappingDefinition bind(ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context) {
    if (resultSetMappingSource.getName() == null) {
        throw new MappingException("ResultSet mapping did not specify name", context.getOrigin());
    }
    final ResultSetMappingDefinition binding = new ResultSetMappingDefinition(resultSetMappingSource.getName());
    bind(resultSetMappingSource, binding, context);
    return binding;
}
Also used : MappingException(org.hibernate.boot.MappingException) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 12 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class ModelBinder method bindMapKey.

private void bindMapKey(final MappingDocument mappingDocument, final IndexedPluralAttributeSource pluralAttributeSource, final org.hibernate.mapping.Map collectionBinding) {
    if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic) {
        final PluralAttributeMapKeySourceBasic mapKeySource = (PluralAttributeMapKeySourceBasic) pluralAttributeSource.getIndexSource();
        final SimpleValue value = new SimpleValue(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        bindSimpleValueType(mappingDocument, mapKeySource.getTypeInformation(), value);
        if (!value.isTypeSpecified()) {
            throw new MappingException("map index element must specify a type: " + pluralAttributeSource.getAttributeRole().getFullPath(), mappingDocument.getOrigin());
        }
        relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), value, true, new RelationalObjectBinder.ColumnNamingDelegate() {

            @Override
            public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
                return database.toIdentifier(IndexedCollection.DEFAULT_INDEX_COLUMN_NAME);
            }
        });
        collectionBinding.setIndex(value);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded) {
        final PluralAttributeMapKeySourceEmbedded mapKeySource = (PluralAttributeMapKeySourceEmbedded) pluralAttributeSource.getIndexSource();
        final Component componentBinding = new Component(mappingDocument.getMetadataCollector(), collectionBinding);
        bindComponent(mappingDocument, mapKeySource.getEmbeddableSource(), componentBinding, null, pluralAttributeSource.getName(), mapKeySource.getXmlNodeName(), false);
        collectionBinding.setIndex(componentBinding);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource) {
        final PluralAttributeMapKeyManyToManySource mapKeySource = (PluralAttributeMapKeyManyToManySource) pluralAttributeSource.getIndexSource();
        final ManyToOne mapKeyBinding = new ManyToOne(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        mapKeyBinding.setReferencedEntityName(mapKeySource.getReferencedEntityName());
        relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), mapKeyBinding, true, new RelationalObjectBinder.ColumnNamingDelegate() {

            @Override
            public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
                return implicitNamingStrategy.determineMapKeyColumnName(new ImplicitMapKeyColumnNameSource() {

                    @Override
                    public AttributePath getPluralAttributePath() {
                        return pluralAttributeSource.getAttributePath();
                    }

                    @Override
                    public MetadataBuildingContext getBuildingContext() {
                        return context;
                    }
                });
            }
        });
        collectionBinding.setIndex(mapKeyBinding);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource) {
        final PluralAttributeMapKeyManyToAnySource mapKeySource = (PluralAttributeMapKeyManyToAnySource) pluralAttributeSource.getIndexSource();
        final Any mapKeyBinding = new Any(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        bindAny(mappingDocument, mapKeySource, mapKeyBinding, pluralAttributeSource.getAttributeRole().append("key"), pluralAttributeSource.getAttributePath().append("key"));
        collectionBinding.setIndex(mapKeyBinding);
    }
}
Also used : PluralAttributeMapKeyManyToAnySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToAnySource) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException) Identifier(org.hibernate.boot.model.naming.Identifier) PluralAttributeMapKeySourceEmbedded(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceEmbedded) PluralAttributeMapKeyManyToManySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToManySource) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Component(org.hibernate.mapping.Component) ImplicitMapKeyColumnNameSource(org.hibernate.boot.model.naming.ImplicitMapKeyColumnNameSource) PluralAttributeMapKeySourceBasic(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceBasic)

Example 13 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class ModelBinder method bindEntityVersion.

private void bindEntityVersion(MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
    final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource();
    final SimpleValue versionValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
    versionValue.makeVersion();
    bindSimpleValueType(sourceDocument, versionAttributeSource.getTypeInformation(), versionValue);
    relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {

        @Override
        public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
            return implicitNamingStrategy.determineBasicColumnName(versionAttributeSource);
        }
    });
    Property prop = new Property();
    prop.setValue(versionValue);
    bindProperty(sourceDocument, versionAttributeSource, prop);
    // but just to make sure...
    if (prop.getValueGenerationStrategy() != null) {
        if (prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT) {
            throw new MappingException("'generated' attribute cannot be 'insert' for version/timestamp property", sourceDocument.getOrigin());
        }
    }
    if (versionAttributeSource.getUnsavedValue() != null) {
        versionValue.setNullValue(versionAttributeSource.getUnsavedValue());
    } else {
        versionValue.setNullValue("undefined");
    }
    rootEntityDescriptor.setVersion(prop);
    rootEntityDescriptor.setDeclaredVersion(prop);
    rootEntityDescriptor.addProperty(prop);
}
Also used : VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) Identifier(org.hibernate.boot.model.naming.Identifier) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException)

Example 14 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class ModelBinder method bindDiscriminatorSubclassEntity.

private void bindDiscriminatorSubclassEntity(SubclassEntitySourceImpl entitySource, SingleTableSubclass entityDescriptor) {
    bindBasicEntityValues(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    final String superEntityName = ((EntitySource) entitySource.getSuperType()).getEntityNamingSource().getEntityName();
    final EntityTableXref superEntityTableXref = entitySource.getLocalMetadataBuildingContext().getMetadataCollector().getEntityTableXref(superEntityName);
    if (superEntityTableXref == null) {
        throw new MappingException(String.format(Locale.ENGLISH, "Unable to locate entity table xref for entity [%s] super-type [%s]", entityDescriptor.getEntityName(), superEntityName), entitySource.origin());
    }
    entitySource.getLocalMetadataBuildingContext().getMetadataCollector().addEntityTableXref(entitySource.getEntityNamingSource().getEntityName(), database.toIdentifier(entitySource.getLocalMetadataBuildingContext().getMetadataCollector().getLogicalTableName(entityDescriptor.getTable())), entityDescriptor.getTable(), superEntityTableXref);
    bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    bindDiscriminatorSubclassEntities(entitySource, entityDescriptor);
}
Also used : EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) MappingException(org.hibernate.boot.MappingException)

Example 15 with MappingException

use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.

the class RelationalValueSourceHelper method buildColumnSources.

/**
	 * Given a {@link ColumnsAndFormulasSource}, build the corresponding list of
	 * {@link ColumnSource}.  Any formula, rather than a column, will result in an exception.
	 *
	 * @param mappingDocument the mapping document
	 * @param containingTableName The logical name of the table containing the relational values
	 * @param columnsAndFormulasSource the adapter describing the value sources.
	 *
	 * @return The corresponding list.
	 */
public static List<ColumnSource> buildColumnSources(MappingDocument mappingDocument, String containingTableName, RelationalValueSourceHelper.ColumnsAndFormulasSource columnsAndFormulasSource) {
    final List<RelationalValueSource> sources = buildValueSources(mappingDocument, containingTableName, columnsAndFormulasSource);
    final List<ColumnSource> columnSources = CollectionHelper.arrayList(sources.size());
    for (RelationalValueSource source : sources) {
        if (!ColumnSource.class.isInstance(source)) {
            final String errorMessage;
            if (columnsAndFormulasSource.getSourceType().canBeNamed() && StringHelper.isNotEmpty(columnsAndFormulasSource.getSourceName())) {
                errorMessage = String.format(Locale.ENGLISH, "Expecting only columns in context of <%s name=\"%s\"/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), columnsAndFormulasSource.getSourceName(), ((DerivedValueSource) source).getExpression());
            } else {
                errorMessage = String.format(Locale.ENGLISH, "Expecting only columns in context of <%s/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), ((DerivedValueSource) source).getExpression());
            }
            throw new MappingException(errorMessage, mappingDocument.getOrigin());
        }
        columnSources.add((ColumnSource) source);
    }
    return columnSources;
}
Also used : RelationalValueSource(org.hibernate.boot.model.source.spi.RelationalValueSource) DerivedValueSource(org.hibernate.boot.model.source.spi.DerivedValueSource) ColumnSource(org.hibernate.boot.model.source.spi.ColumnSource) MappingException(org.hibernate.boot.MappingException)

Aggregations

MappingException (org.hibernate.boot.MappingException)22 Identifier (org.hibernate.boot.model.naming.Identifier)7 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)4 RelationalValueSource (org.hibernate.boot.model.source.spi.RelationalValueSource)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Property (org.hibernate.mapping.Property)3 HashSet (java.util.HashSet)2 List (java.util.List)2 JAXBException (javax.xml.bind.JAXBException)2 JaxbHbmNativeQueryPropertyReturnType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryPropertyReturnType)2 ColumnSource (org.hibernate.boot.model.source.spi.ColumnSource)2 DerivedValueSource (org.hibernate.boot.model.source.spi.DerivedValueSource)2 VersionAttributeSource (org.hibernate.boot.model.source.spi.VersionAttributeSource)2 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)2 FilterDefinition (org.hibernate.engine.spi.FilterDefinition)2 Component (org.hibernate.mapping.Component)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 SimpleValue (org.hibernate.mapping.SimpleValue)2 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)2