Search in sources :

Example 41 with HibernateException

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

the class IlikeExpression method toSqlString.

@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
    final Dialect dialect = criteriaQuery.getFactory().getDialect();
    final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
    if (columns.length != 1) {
        throw new HibernateException("ilike may only be used with single-column properties");
    }
    if (dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) {
        return columns[0] + " ilike ?";
    } else {
        return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
    }
}
Also used : PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) HibernateException(org.hibernate.HibernateException) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Dialect(org.hibernate.dialect.Dialect) PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect)

Example 42 with HibernateException

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

the class DriverManagerConnectionProviderImpl method buildCreator.

private ConnectionCreator buildCreator(Map configurationValues) {
    final ConnectionCreatorBuilder connectionCreatorBuilder = new ConnectionCreatorBuilder(serviceRegistry);
    final String driverClassName = (String) configurationValues.get(AvailableSettings.DRIVER);
    connectionCreatorBuilder.setDriver(loadDriverIfPossible(driverClassName));
    final String url = (String) configurationValues.get(AvailableSettings.URL);
    if (url == null) {
        final String msg = log.jdbcUrlNotSpecified(AvailableSettings.URL);
        log.error(msg);
        throw new HibernateException(msg);
    }
    connectionCreatorBuilder.setUrl(url);
    log.usingDriver(driverClassName, url);
    final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties(configurationValues);
    // if debug level is enabled, then log the password, otherwise mask it
    if (log.isDebugEnabled()) {
        log.connectionProperties(connectionProps);
    } else {
        log.connectionProperties(ConfigurationHelper.maskOut(connectionProps, "password"));
    }
    connectionCreatorBuilder.setConnectionProps(connectionProps);
    final boolean autoCommit = ConfigurationHelper.getBoolean(AvailableSettings.AUTOCOMMIT, configurationValues, false);
    log.autoCommitMode(autoCommit);
    connectionCreatorBuilder.setAutoCommit(autoCommit);
    final Integer isolation = ConnectionProviderInitiator.extractIsolation(configurationValues);
    if (isolation != null) {
        log.jdbcIsolationLevel(ConnectionProviderInitiator.toIsolationNiceName(isolation));
    }
    connectionCreatorBuilder.setIsolation(isolation);
    return connectionCreatorBuilder.build();
}
Also used : HibernateException(org.hibernate.HibernateException) Properties(java.util.Properties)

Example 43 with HibernateException

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

the class PooledConnections method poll.

public Connection poll() throws SQLException {
    Connection conn = availableConnections.poll();
    if (conn == null) {
        synchronized (allConnections) {
            if (allConnections.size() < maxSize) {
                addConnections(1);
                return poll();
            }
        }
        throw new HibernateException("The internal connection pool has reached its maximum size and no connection is currently available!");
    }
    conn.setAutoCommit(autoCommit);
    return conn;
}
Also used : HibernateException(org.hibernate.HibernateException) Connection(java.sql.Connection)

Example 44 with HibernateException

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

the class PessimisticForceIncrementLockingStrategy method lock.

@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
    if (!lockable.isVersioned()) {
        throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
    }
    final EntityEntry entry = session.getPersistenceContext().getEntry(object);
    final EntityPersister persister = entry.getPersister();
    final Object nextVersion = persister.forceVersionIncrement(entry.getId(), entry.getVersion(), session);
    entry.forceLocked(object, nextVersion);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityEntry(org.hibernate.engine.spi.EntityEntry) HibernateException(org.hibernate.HibernateException)

Example 45 with HibernateException

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

the class PessimisticReadUpdateLockingStrategy method lock.

@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
    if (!lockable.isVersioned()) {
        throw new HibernateException("write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]");
    }
    final SessionFactoryImplementor factory = session.getFactory();
    try {
        try {
            final PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql);
            try {
                lockable.getVersionType().nullSafeSet(st, version, 1, session);
                int offset = 2;
                lockable.getIdentifierType().nullSafeSet(st, id, offset, session);
                offset += lockable.getIdentifierType().getColumnSpan(factory);
                if (lockable.isVersioned()) {
                    lockable.getVersionType().nullSafeSet(st, version, offset, session);
                }
                final int affected = session.getJdbcCoordinator().getResultSetReturn().executeUpdate(st);
                // todo:  should this instead check for exactly one row modified?
                if (affected < 0) {
                    if (factory.getStatistics().isStatisticsEnabled()) {
                        factory.getStatistics().optimisticFailure(lockable.getEntityName());
                    }
                    throw new StaleObjectStateException(lockable.getEntityName(), id);
                }
            } finally {
                session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
                session.getJdbcCoordinator().afterStatementExecution();
            }
        } catch (SQLException e) {
            throw session.getJdbcServices().getSqlExceptionHelper().convert(e, "could not lock: " + MessageHelper.infoString(lockable, id, session.getFactory()), sql);
        }
    } catch (JDBCException e) {
        throw new PessimisticEntityLockException(object, "could not obtain pessimistic lock", e);
    }
}
Also used : JDBCException(org.hibernate.JDBCException) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PreparedStatement(java.sql.PreparedStatement) StaleObjectStateException(org.hibernate.StaleObjectStateException)

Aggregations

HibernateException (org.hibernate.HibernateException)609 Session (org.hibernate.Session)285 DAOException (com.tomasio.projects.trainning.exception.DAOException)186 DAOException (org.jbei.ice.storage.DAOException)122 ArrayList (java.util.ArrayList)63 Criteria (org.hibernate.Criteria)56 Test (org.junit.Test)43 Transaction (org.hibernate.Transaction)39 SQLException (java.sql.SQLException)38 SimpleDateFormat (java.text.SimpleDateFormat)22 Query (org.hibernate.Query)20 IOException (java.io.IOException)19 ParseException (java.text.ParseException)18 TestForIssue (org.hibernate.testing.TestForIssue)16 Date (java.util.Date)13 List (java.util.List)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)12 Serializable (java.io.Serializable)11 HashMap (java.util.HashMap)11 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)11