Search in sources :

Example 56 with MappingException

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

the class DefaultIdentifierGeneratorFactory method getIdentifierGeneratorClass.

@Override
public Class getIdentifierGeneratorClass(String strategy) {
    if ("hilo".equals(strategy)) {
        throw new UnsupportedOperationException("Support for 'hilo' generator has been removed");
    }
    String resolvedStrategy = "native".equals(strategy) ? getDialect().getNativeIdentifierGeneratorStrategy() : strategy;
    Class generatorClass = generatorStrategyToClassNameMap.get(resolvedStrategy);
    try {
        if (generatorClass == null) {
            final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
            generatorClass = cls.classForName(resolvedStrategy);
        }
    } catch (ClassLoadingException e) {
        throw new MappingException(String.format("Could not interpret id generator strategy [%s]", strategy));
    }
    return generatorClass;
}
Also used : ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) MappingException(org.hibernate.MappingException)

Example 57 with MappingException

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

the class SessionImpl method find.

@Override
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) {
    checkOpen();
    LockOptions lockOptions = null;
    try {
        if (properties != null && !properties.isEmpty()) {
            getLoadQueryInfluencers().setFetchGraph((EntityGraph) properties.get(QueryHints.HINT_FETCHGRAPH));
            getLoadQueryInfluencers().setLoadGraph((EntityGraph) properties.get(QueryHints.HINT_LOADGRAPH));
        }
        final IdentifierLoadAccess<T> loadAccess = byId(entityClass);
        loadAccess.with(determineAppropriateLocalCacheMode(properties));
        if (lockModeType != null) {
            if (!LockModeType.NONE.equals(lockModeType)) {
                checkTransactionNeeded();
            }
            lockOptions = buildLockOptions(lockModeType, properties);
            loadAccess.with(lockOptions);
        }
        return loadAccess.load((Serializable) primaryKey);
    } catch (EntityNotFoundException ignored) {
        // which find() should not throw.  Find() should return null if the entity was not found.
        if (log.isDebugEnabled()) {
            String entityName = entityClass != null ? entityClass.getName() : null;
            String identifierValue = primaryKey != null ? primaryKey.toString() : null;
            log.ignoringEntityNotFound(entityName, identifierValue);
        }
        return null;
    } catch (ObjectDeletedException e) {
        //the spec is silent about people doing remove() find() on the same PC
        return null;
    } catch (ObjectNotFoundException e) {
        //should not happen on the entity itself with get
        throw new IllegalArgumentException(e.getMessage(), e);
    } catch (MappingException | TypeMismatchException | ClassCastException e) {
        throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
    } catch (RuntimeException e) {
        throw exceptionConverter.convert(e, lockOptions);
    } finally {
        getLoadQueryInfluencers().setFetchGraph(null);
        getLoadQueryInfluencers().setLoadGraph(null);
    }
}
Also used : LockOptions(org.hibernate.LockOptions) TypeMismatchException(org.hibernate.TypeMismatchException) EntityNotFoundException(javax.persistence.EntityNotFoundException) UnknownSqlResultSetMappingException(org.hibernate.procedure.UnknownSqlResultSetMappingException) MappingException(org.hibernate.MappingException) JPA_LOCK_TIMEOUT(org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) ObjectDeletedException(org.hibernate.ObjectDeletedException)

Example 58 with MappingException

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

the class SessionImpl method fireMerge.

private Object fireMerge(MergeEvent event) {
    try {
        checkTransactionSynchStatus();
        checkNoUnresolvedActionsBeforeOperation();
        for (MergeEventListener listener : listeners(EventType.MERGE)) {
            listener.onMerge(event);
        }
        checkNoUnresolvedActionsAfterOperation();
    } catch (ObjectDeletedException sse) {
        throw exceptionConverter.convert(new IllegalArgumentException(sse));
    } catch (MappingException e) {
        throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
    } catch (RuntimeException e) {
        //including HibernateException
        throw exceptionConverter.convert(e);
    }
    return event.getResult();
}
Also used : ObjectDeletedException(org.hibernate.ObjectDeletedException) MergeEventListener(org.hibernate.event.spi.MergeEventListener) UnknownSqlResultSetMappingException(org.hibernate.procedure.UnknownSqlResultSetMappingException) MappingException(org.hibernate.MappingException)

Example 59 with MappingException

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

the class SessionImpl method refresh.

@Override
public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> properties) {
    checkOpen();
    final CacheMode previousCacheMode = getCacheMode();
    final CacheMode refreshCacheMode = determineAppropriateLocalCacheMode(properties);
    LockOptions lockOptions = null;
    try {
        setCacheMode(refreshCacheMode);
        if (!contains(entity)) {
            throw exceptionConverter.convert(new IllegalArgumentException("Entity not managed"));
        }
        if (lockModeType != null) {
            if (!LockModeType.NONE.equals(lockModeType)) {
                checkTransactionNeeded();
            }
            lockOptions = buildLockOptions(lockModeType, properties);
            refresh(entity, lockOptions);
        } else {
            refresh(entity);
        }
    } catch (MappingException e) {
        throw exceptionConverter.convert(new IllegalArgumentException(e.getMessage(), e));
    } catch (RuntimeException e) {
        throw exceptionConverter.convert(e, lockOptions);
    } finally {
        setCacheMode(previousCacheMode);
    }
}
Also used : LockOptions(org.hibernate.LockOptions) CacheMode(org.hibernate.CacheMode) UnknownSqlResultSetMappingException(org.hibernate.procedure.UnknownSqlResultSetMappingException) MappingException(org.hibernate.MappingException)

Example 60 with MappingException

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

the class AbstractPropertyMapping method initPropertyPaths.

/*protected void initPropertyPaths(
			final String path,
			final Type type,
			final String[] columns,
			final String[] formulaTemplates,
			final Mapping factory)
	throws MappingException {
		//addFormulaPropertyPath(path, type, formulaTemplates);
		initPropertyPaths(path, type, columns, formulaTemplates, factory);
	}*/
protected void initPropertyPaths(final String path, final Type type, String[] columns, String[] columnReaders, String[] columnReaderTemplates, final String[] formulaTemplates, final Mapping factory) throws MappingException {
    assert columns != null : "Incoming columns should not be null : " + path;
    assert type != null : "Incoming type should not be null : " + path;
    if (columns.length != type.getColumnSpan(factory)) {
        throw new MappingException("broken column mapping for: " + path + " of: " + getEntityName());
    }
    if (type.isAssociationType()) {
        AssociationType actype = (AssociationType) type;
        if (actype.useLHSPrimaryKey()) {
            columns = getIdentifierColumnNames();
            columnReaders = getIdentifierColumnReaders();
            columnReaderTemplates = getIdentifierColumnReaderTemplates();
        } else {
            String foreignKeyProperty = actype.getLHSPropertyName();
            if (foreignKeyProperty != null && !path.equals(foreignKeyProperty)) {
                //TODO: this requires that the collection is defined afterQuery the
                //      referenced property in the mapping file (ok?)
                columns = columnsByPropertyPath.get(foreignKeyProperty);
                if (columns == null) {
                    //get em on the second pass!
                    return;
                }
                columnReaders = columnReadersByPropertyPath.get(foreignKeyProperty);
                columnReaderTemplates = columnReaderTemplatesByPropertyPath.get(foreignKeyProperty);
            }
        }
    }
    if (path != null) {
        addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates);
    }
    if (type.isComponentType()) {
        CompositeType actype = (CompositeType) type;
        initComponentPropertyPaths(path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
        if (actype.isEmbedded()) {
            initComponentPropertyPaths(path == null ? null : StringHelper.qualifier(path), actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
        }
    } else if (type.isEntityType()) {
        initIdentifierPropertyPaths(path, (EntityType) type, columns, columnReaders, columnReaderTemplates, factory);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) AssociationType(org.hibernate.type.AssociationType) MappingException(org.hibernate.MappingException) CompositeType(org.hibernate.type.CompositeType)

Aggregations

MappingException (org.hibernate.MappingException)94 PersistentClass (org.hibernate.mapping.PersistentClass)17 HibernateException (org.hibernate.HibernateException)12 Iterator (java.util.Iterator)11 Test (org.junit.Test)11 AnnotationException (org.hibernate.AnnotationException)10 QueryException (org.hibernate.QueryException)10 Type (org.hibernate.type.Type)10 Property (org.hibernate.mapping.Property)9 HashMap (java.util.HashMap)8 XClass (org.hibernate.annotations.common.reflection.XClass)8 DuplicateMappingException (org.hibernate.DuplicateMappingException)6 Configuration (org.hibernate.cfg.Configuration)6 UnknownSqlResultSetMappingException (org.hibernate.procedure.UnknownSqlResultSetMappingException)6 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 Map (java.util.Map)5 AssociationType (org.hibernate.type.AssociationType)5 HashSet (java.util.HashSet)4 ClassLoadingException (org.hibernate.annotations.common.reflection.ClassLoadingException)4 MetadataSources (org.hibernate.boot.MetadataSources)4