Search in sources :

Example 46 with HibernateException

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

the class OnLockVisitor method processCollection.

@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
    if (collection == null) {
        return null;
    }
    final SessionImplementor session = getSession();
    final CollectionPersister persister = session.getFactory().getCollectionPersister(type.getRole());
    if (collection instanceof PersistentCollection) {
        final PersistentCollection persistentCollection = (PersistentCollection) collection;
        if (persistentCollection.setCurrentSession(session)) {
            if (isOwnerUnchanged(persistentCollection, persister, extractCollectionKeyFromOwner(persister))) {
                // a "detached" collection that originally belonged to the same entity
                if (persistentCollection.isDirty()) {
                    throw new HibernateException("reassociated object has dirty collection");
                }
                reattachCollection(persistentCollection, type);
            } else {
                // a "detached" collection that belonged to a different entity
                throw new HibernateException("reassociated object has dirty collection reference");
            }
        } else {
            // to the entity passed to update()
            throw new HibernateException("reassociated object has dirty collection reference");
        }
    } else {
        //TODO: or an array!! we can't lock objects with arrays now??
        throw new HibernateException("reassociated object has dirty collection reference (or an array)");
    }
    return null;
}
Also used : PersistentCollection(org.hibernate.collection.spi.PersistentCollection) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) HibernateException(org.hibernate.HibernateException) SessionImplementor(org.hibernate.engine.spi.SessionImplementor)

Example 47 with HibernateException

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

the class FilterImpl method setParameterList.

/**
	 * Set the named parameter's value list for this filter.  Used
	 * in conjunction with IN-style filter criteria.
	 *
	 * @param name   The parameter's name.
	 * @param values The values to be expanded into an SQL IN list.
	 * @return This FilterImpl instance (for method chaining).
	 */
public Filter setParameterList(String name, Collection values) throws HibernateException {
    // Make sure this is a defined parameter and check the incoming value type
    if (values == null) {
        throw new IllegalArgumentException("Collection must be not null!");
    }
    Type type = definition.getParameterType(name);
    if (type == null) {
        throw new HibernateException("Undefined filter parameter [" + name + "]");
    }
    if (!values.isEmpty()) {
        Class elementClass = values.iterator().next().getClass();
        if (!type.getReturnedClass().isAssignableFrom(elementClass)) {
            throw new HibernateException("Incorrect type for parameter [" + name + "]");
        }
    }
    parameters.put(name, values);
    return this;
}
Also used : Type(org.hibernate.type.Type) HibernateException(org.hibernate.HibernateException)

Example 48 with HibernateException

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

the class GUIDGenerator method generate.

public Serializable generate(SharedSessionContractImplementor session, Object obj) throws HibernateException {
    final String sql = session.getJdbcServices().getJdbcEnvironment().getDialect().getSelectGUIDString();
    try {
        PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql);
        try {
            ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract(st);
            final String result;
            try {
                if (!rs.next()) {
                    throw new HibernateException("The database returned no GUID identity value");
                }
                result = rs.getString(1);
            } finally {
                session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(rs, st);
            }
            LOG.guidGenerated(result);
            return result;
        } finally {
            session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
            session.getJdbcCoordinator().afterStatementExecution();
        }
    } catch (SQLException sqle) {
        throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not retrieve GUID", sql);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 49 with HibernateException

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

the class UUIDGenerator method configure.

@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    // check first for the strategy instance
    strategy = (UUIDGenerationStrategy) params.get(UUID_GEN_STRATEGY);
    if (strategy == null) {
        // next check for the strategy class
        final String strategyClassName = params.getProperty(UUID_GEN_STRATEGY_CLASS);
        if (strategyClassName != null) {
            try {
                final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
                final Class strategyClass = cls.classForName(strategyClassName);
                try {
                    strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
                } catch (Exception ignore) {
                    LOG.unableToInstantiateUuidGenerationStrategy(ignore);
                }
            } catch (ClassLoadingException ignore) {
                LOG.unableToLocateUuidGenerationStrategy(strategyClassName);
            }
        }
    }
    if (strategy == null) {
        // lastly use the standard random generator
        strategy = StandardRandomStrategy.INSTANCE;
    }
    if (UUID.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
    } else if (String.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
    } else if (byte[].class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
    } else {
        throw new HibernateException("Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion");
    }
}
Also used : HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 50 with HibernateException

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

the class SessionImpl method doFlush.

private void doFlush() {
    checkTransactionNeeded();
    checkTransactionSynchStatus();
    try {
        if (persistenceContext.getCascadeLevel() > 0) {
            throw new HibernateException("Flush during cascade is dangerous");
        }
        FlushEvent flushEvent = new FlushEvent(this);
        for (FlushEventListener listener : listeners(EventType.FLUSH)) {
            listener.onFlush(flushEvent);
        }
        delayedAfterCompletion();
    } catch (RuntimeException e) {
        throw exceptionConverter.convert(e);
    }
}
Also used : AutoFlushEventListener(org.hibernate.event.spi.AutoFlushEventListener) FlushEventListener(org.hibernate.event.spi.FlushEventListener) FlushEvent(org.hibernate.event.spi.FlushEvent) AutoFlushEvent(org.hibernate.event.spi.AutoFlushEvent) HibernateException(org.hibernate.HibernateException)

Aggregations

HibernateException (org.hibernate.HibernateException)372 DAOException (org.jbei.ice.storage.DAOException)141 Session (org.hibernate.Session)72 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)27 IOException (java.io.IOException)15 TestForIssue (org.hibernate.testing.TestForIssue)15 Transaction (org.hibernate.Transaction)14 Group (org.jbei.ice.storage.model.Group)14 Type (org.hibernate.type.Type)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 HashMap (java.util.HashMap)9 Method (java.lang.reflect.Method)8 Dialect (org.hibernate.dialect.Dialect)8 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)8 HibernateProxy (org.hibernate.proxy.HibernateProxy)8