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;
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations