use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class ScanningCoordinator method applyScanResultsToManagedResources.
public void applyScanResultsToManagedResources(ManagedResourcesImpl managedResources, ScanResult scanResult, MetadataBuildingOptions options, XmlMappingBinderAccess xmlMappingBinderAccess) {
final ScanEnvironment scanEnvironment = options.getScanEnvironment();
final ServiceRegistry serviceRegistry = options.getServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
// mapping files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final Set<String> nonLocatedMappingFileNames = new HashSet<String>();
final List<String> explicitMappingFileNames = scanEnvironment.getExplicitlyListedMappingFiles();
if (explicitMappingFileNames != null) {
nonLocatedMappingFileNames.addAll(explicitMappingFileNames);
}
for (MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles()) {
managedResources.addXmlBinding(xmlMappingBinderAccess.bind(mappingFileDescriptor.getStreamAccess()));
nonLocatedMappingFileNames.remove(mappingFileDescriptor.getName());
}
for (String name : nonLocatedMappingFileNames) {
final URL url = classLoaderService.locateResource(name);
if (url == null) {
throw new MappingException("Unable to resolve explicitly named mapping-file : " + name, new Origin(SourceType.RESOURCE, name));
}
final UrlInputStreamAccess inputStreamAccess = new UrlInputStreamAccess(url);
managedResources.addXmlBinding(xmlMappingBinderAccess.bind(inputStreamAccess));
}
// classes and packages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final List<String> unresolvedListedClassNames = scanEnvironment.getExplicitlyListedClassNames() == null ? new ArrayList<String>() : new ArrayList<String>(scanEnvironment.getExplicitlyListedClassNames());
for (ClassDescriptor classDescriptor : scanResult.getLocatedClasses()) {
if (classDescriptor.getCategorization() == ClassDescriptor.Categorization.CONVERTER) {
// converter classes are safe to load because we never enhance them,
// and notice we use the ClassLoaderService specifically, not the temp ClassLoader (if any)
managedResources.addAttributeConverterDefinition(AttributeConverterDefinition.from(classLoaderService.<AttributeConverter>classForName(classDescriptor.getName())));
} else if (classDescriptor.getCategorization() == ClassDescriptor.Categorization.MODEL) {
managedResources.addAnnotatedClassName(classDescriptor.getName());
}
unresolvedListedClassNames.remove(classDescriptor.getName());
}
// IMPL NOTE : "explicitlyListedClassNames" can contain class or package names...
for (PackageDescriptor packageDescriptor : scanResult.getLocatedPackages()) {
managedResources.addAnnotatedPackageName(packageDescriptor.getName());
unresolvedListedClassNames.remove(packageDescriptor.getName());
}
for (String unresolvedListedClassName : unresolvedListedClassNames) {
// because the explicit list can contain either class names or package names
// we need to check for both here...
// First, try it as a class name
final String classFileName = unresolvedListedClassName.replace('.', '/') + ".class";
final URL classFileUrl = classLoaderService.locateResource(classFileName);
if (classFileUrl != null) {
managedResources.addAnnotatedClassName(unresolvedListedClassName);
continue;
}
// Then, try it as a package name
final String packageInfoFileName = unresolvedListedClassName.replace('.', '/') + "/package-info.class";
final URL packageInfoFileUrl = classLoaderService.locateResource(packageInfoFileName);
if (packageInfoFileUrl != null) {
managedResources.addAnnotatedPackageName(unresolvedListedClassName);
continue;
}
log.debugf("Unable to resolve class [%s] named in persistence unit [%s]", unresolvedListedClassName, scanEnvironment.getRootUrl());
}
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class EntityHierarchySourceImpl method processSubclass.
public void processSubclass(SubclassEntitySourceImpl subclassEntitySource) {
final InheritanceType inheritanceType = Helper.interpretInheritanceType(subclassEntitySource.jaxbEntityMapping());
if (hierarchyInheritanceType == InheritanceType.NO_INHERITANCE) {
hierarchyInheritanceType = inheritanceType;
} else if (hierarchyInheritanceType != inheritanceType) {
throw new MappingException("Mixed inheritance strategies not supported", subclassEntitySource.getOrigin());
}
collectedEntityNames.add(subclassEntitySource.getEntityNamingSource().getEntityName());
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class EntityHierarchySourceImpl method interpretDiscriminatorSource.
private static DiscriminatorSource interpretDiscriminatorSource(final RootEntitySourceImpl rootEntitySource) {
final JaxbHbmEntityDiscriminatorType jaxbDiscriminatorMapping = rootEntitySource.jaxbEntityMapping().getDiscriminator();
if (jaxbDiscriminatorMapping == null) {
return null;
}
final RelationalValueSource relationalValueSource = RelationalValueSourceHelper.buildValueSource(rootEntitySource.sourceMappingDocument(), null, new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
@Override
public XmlElementMetadata getSourceType() {
return XmlElementMetadata.DISCRIMINATOR;
}
@Override
public String getSourceName() {
return null;
}
@Override
public SizeSource getSizeSource() {
return Helper.interpretSizeSource(jaxbDiscriminatorMapping.getLength(), (Integer) null, null);
}
@Override
public String getFormulaAttribute() {
return jaxbDiscriminatorMapping.getFormulaAttribute();
}
@Override
public String getColumnAttribute() {
return jaxbDiscriminatorMapping.getColumnAttribute();
}
private List columnOrFormulas;
@Override
public List getColumnOrFormulaElements() {
if (columnOrFormulas == null) {
if (jaxbDiscriminatorMapping.getColumn() != null) {
if (jaxbDiscriminatorMapping.getFormula() != null) {
throw new MappingException(String.format(Locale.ENGLISH, "discriminator mapping [%s] named both <column/> and <formula/>, but only one or other allowed", rootEntitySource.getEntityNamingSource().getEntityName()), rootEntitySource.sourceMappingDocument().getOrigin());
} else {
columnOrFormulas = Collections.singletonList(jaxbDiscriminatorMapping.getColumn());
}
} else {
if (jaxbDiscriminatorMapping.getFormula() != null) {
columnOrFormulas = Collections.singletonList(jaxbDiscriminatorMapping.getFormula());
} else {
columnOrFormulas = Collections.emptyList();
}
}
}
return columnOrFormulas;
}
@Override
public Boolean isNullable() {
return !jaxbDiscriminatorMapping.isNotNull();
}
});
return new DiscriminatorSource() {
@Override
public EntityNaming getEntityNaming() {
return rootEntitySource.getEntityNamingSource();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return rootEntitySource.metadataBuildingContext();
}
@Override
public RelationalValueSource getDiscriminatorRelationalValueSource() {
return relationalValueSource;
}
@Override
public String getExplicitHibernateTypeName() {
return jaxbDiscriminatorMapping.getType();
}
@Override
public boolean isForced() {
return jaxbDiscriminatorMapping.isForce();
}
@Override
public boolean isInserted() {
return jaxbDiscriminatorMapping.isInsert();
}
};
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class CacheableFileXmlSource method doBind.
@Override
@SuppressWarnings("unchecked")
public Binding doBind(Binder binder) {
if (strict) {
try {
return new Binding(readSerFile(), getOrigin());
} catch (SerializationException e) {
throw new MappingException(String.format("Unable to deserialize from cached file [%s]", getOrigin().getName()), e, getOrigin());
} catch (FileNotFoundException e) {
throw new MappingException(String.format("Unable to locate cached file [%s]", getOrigin().getName()), e, getOrigin());
}
} else {
if (!isSerfileObsolete()) {
try {
return readSerFile();
} catch (SerializationException e) {
log.unableToDeserializeCache(serFile.getName(), e);
} catch (FileNotFoundException e) {
log.cachedFileNotFound(serFile.getName(), e);
}
} else {
log.cachedFileObsolete(serFile);
}
log.readingMappingsFromFile(xmlFile.getPath());
final Binding binding = FileXmlSource.doBind(binder, xmlFile, getOrigin());
writeSerFile(binding);
return binding;
}
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class ModelBinder method bindBasicEntityValues.
private void bindBasicEntityValues(MappingDocument sourceDocument, AbstractEntitySourceImpl entitySource, PersistentClass entityDescriptor) {
entityDescriptor.setEntityName(entitySource.getEntityNamingSource().getEntityName());
entityDescriptor.setJpaEntityName(entitySource.getEntityNamingSource().getJpaEntityName());
entityDescriptor.setClassName(entitySource.getEntityNamingSource().getClassName());
entityDescriptor.setDiscriminatorValue(entitySource.getDiscriminatorMatchValue() != null ? entitySource.getDiscriminatorMatchValue() : entityDescriptor.getEntityName());
// NOTE : entitySource#isLazy already accounts for MappingDefaults#areEntitiesImplicitlyLazy
if (StringHelper.isNotEmpty(entitySource.getProxy())) {
final String qualifiedProxyName = sourceDocument.qualifyClassName(entitySource.getProxy());
entityDescriptor.setProxyInterfaceName(qualifiedProxyName);
entityDescriptor.setLazy(true);
} else if (entitySource.isLazy()) {
entityDescriptor.setProxyInterfaceName(entityDescriptor.getClassName());
entityDescriptor.setLazy(true);
} else {
entityDescriptor.setProxyInterfaceName(null);
entityDescriptor.setLazy(false);
}
entityDescriptor.setAbstract(entitySource.isAbstract());
sourceDocument.getMetadataCollector().addImport(entitySource.getEntityNamingSource().getEntityName(), entitySource.getEntityNamingSource().getEntityName());
if (sourceDocument.getMappingDefaults().isAutoImportEnabled() && entitySource.getEntityNamingSource().getEntityName().indexOf('.') > 0) {
sourceDocument.getMetadataCollector().addImport(StringHelper.unqualify(entitySource.getEntityNamingSource().getEntityName()), entitySource.getEntityNamingSource().getEntityName());
}
if (entitySource.getTuplizerClassMap() != null) {
if (entitySource.getTuplizerClassMap().size() > 1) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfMultipleEntityModeSupport();
}
for (Map.Entry<EntityMode, String> tuplizerEntry : entitySource.getTuplizerClassMap().entrySet()) {
entityDescriptor.addTuplizer(tuplizerEntry.getKey(), tuplizerEntry.getValue());
}
}
if (StringHelper.isNotEmpty(entitySource.getXmlNodeName())) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
}
entityDescriptor.setDynamicInsert(entitySource.isDynamicInsert());
entityDescriptor.setDynamicUpdate(entitySource.isDynamicUpdate());
entityDescriptor.setBatchSize(entitySource.getBatchSize());
entityDescriptor.setSelectBeforeUpdate(entitySource.isSelectBeforeUpdate());
if (StringHelper.isNotEmpty(entitySource.getCustomPersisterClassName())) {
try {
entityDescriptor.setEntityPersisterClass(sourceDocument.getBootstrapContext().getClassLoaderAccess().classForName(entitySource.getCustomPersisterClassName()));
} catch (ClassLoadingException e) {
throw new MappingException(String.format(Locale.ENGLISH, "Unable to load specified persister class : %s", entitySource.getCustomPersisterClassName()), e, sourceDocument.getOrigin());
}
}
bindCustomSql(sourceDocument, entitySource, entityDescriptor);
final JdbcEnvironment jdbcEnvironment = sourceDocument.getMetadataCollector().getDatabase().getJdbcEnvironment();
for (String tableName : entitySource.getSynchronizedTableNames()) {
final Identifier physicalTableName = sourceDocument.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(jdbcEnvironment.getIdentifierHelper().toIdentifier(tableName), jdbcEnvironment);
entityDescriptor.addSynchronizedTable(physicalTableName.render(jdbcEnvironment.getDialect()));
}
for (FilterSource filterSource : entitySource.getFilterSources()) {
String condition = filterSource.getCondition();
if (condition == null) {
final FilterDefinition filterDefinition = sourceDocument.getMetadataCollector().getFilterDefinition(filterSource.getName());
if (filterDefinition != null) {
condition = filterDefinition.getDefaultFilterCondition();
}
}
entityDescriptor.addFilter(filterSource.getName(), condition, filterSource.shouldAutoInjectAliases(), filterSource.getAliasToTableMap(), filterSource.getAliasToEntityMap());
}
for (JaxbHbmNamedQueryType namedQuery : entitySource.getNamedQueries()) {
NamedQueryBinder.processNamedQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
for (JaxbHbmNamedNativeQueryType namedQuery : entitySource.getNamedNativeQueries()) {
NamedQueryBinder.processNamedNativeQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
entityDescriptor.setMetaAttributes(entitySource.getToolingHintContext().getMetaAttributeMap());
}
Aggregations