Search in sources :

Example 56 with HibernateException

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

the class ConfigHelper method getConfigStream.

/**
	 * Open an InputStream to the URL represented by the incoming path.  First makes a call
	 * to {@link #locateConfig(java.lang.String)} in order to find an appropriate URL.
	 * {@link java.net.URL#openStream()} is then called to obtain the stream.
	 *
	 * @param path The path representing the config location.
	 *
	 * @return An input stream to the requested config resource.
	 *
	 * @throws HibernateException Unable to open stream to that resource.
	 */
public static InputStream getConfigStream(final String path) throws HibernateException {
    final URL url = ConfigHelper.locateConfig(path);
    if (url == null) {
        String msg = LOG.unableToLocateConfigFile(path);
        LOG.error(msg);
        throw new HibernateException(msg);
    }
    try {
        return url.openStream();
    } catch (IOException e) {
        throw new HibernateException("Unable to open config file: " + path, e);
    }
}
Also used : HibernateException(org.hibernate.HibernateException) IOException(java.io.IOException) URL(java.net.URL)

Example 57 with HibernateException

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

the class SQLQueryReturnProcessor method processJoinReturn.

private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
    String alias = fetchReturn.getAlias();
    //		if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
    if (alias2Persister.containsKey(alias) || alias2CollectionPersister.containsKey(alias)) {
        // already been processed...
        return;
    }
    String ownerAlias = fetchReturn.getOwnerAlias();
    // Make sure the owner alias is known...
    if (!alias2Return.containsKey(ownerAlias)) {
        throw new HibernateException("Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]");
    }
    // If this return's alias has not been processed yet, do so b4 further processing of this return
    if (!alias2Persister.containsKey(ownerAlias)) {
        NativeSQLQueryNonScalarReturn ownerReturn = (NativeSQLQueryNonScalarReturn) alias2Return.get(ownerAlias);
        processReturn(ownerReturn);
    }
    SQLLoadable ownerPersister = (SQLLoadable) alias2Persister.get(ownerAlias);
    Type returnType = ownerPersister.getPropertyType(fetchReturn.getOwnerProperty());
    if (returnType.isCollectionType()) {
        String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
        addCollection(role, alias, fetchReturn.getPropertyResultsMap());
    //			collectionOwnerAliases.add( ownerAlias );
    } else if (returnType.isEntityType()) {
        EntityType eType = (EntityType) returnType;
        String returnEntityName = eType.getAssociatedEntityName();
        SQLLoadable persister = getSQLLoadable(returnEntityName);
        addPersister(alias, fetchReturn.getPropertyResultsMap(), persister);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) NativeSQLQueryNonScalarReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryNonScalarReturn) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) HibernateException(org.hibernate.HibernateException) SQLLoadable(org.hibernate.persister.entity.SQLLoadable)

Example 58 with HibernateException

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

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingCollection.

@Override
public void startingCollection(CollectionDefinition collectionDefinition) {
    // see if the EntityDefinition is a root...
    final boolean isRoot = fetchSourceStack.isEmpty();
    if (!isRoot) {
        // if not, this call should represent a fetch which should have been handled in #startingAttribute
        return;
    }
    log.tracef("%s Starting root collection : %s", StringHelper.repeat(">>", fetchSourceStack.size()), collectionDefinition.getCollectionPersister().getRole());
    // if we get here, it is a root
    if (!supportsRootCollectionReturns()) {
        throw new HibernateException("This strategy does not support root collection returns");
    }
    final CollectionReturn collectionReturn = new CollectionReturnImpl(collectionDefinition, querySpaces);
    pushToCollectionStack(collectionReturn);
    addRootReturn(collectionReturn);
    associationKeyRegistered(new AssociationKey(((Joinable) collectionDefinition.getCollectionPersister()).getTableName(), ((Joinable) collectionDefinition.getCollectionPersister()).getKeyColumnNames()));
}
Also used : AssociationKey(org.hibernate.persister.walking.spi.AssociationKey) HibernateException(org.hibernate.HibernateException) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Joinable(org.hibernate.persister.entity.Joinable) CollectionReturnImpl(org.hibernate.loader.plan.build.internal.returns.CollectionReturnImpl)

Example 59 with HibernateException

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

the class Loader method prepareQueryStatement.

/**
	 * Obtain a <tt>PreparedStatement</tt> with all parameters pre-bound.
	 * Bind JDBC-style <tt>?</tt> parameters, named parameters, and
	 * limit parameters.
	 */
protected final PreparedStatement prepareQueryStatement(String sql, final QueryParameters queryParameters, final LimitHandler limitHandler, final boolean scroll, final SharedSessionContractImplementor session) throws SQLException, HibernateException {
    final Dialect dialect = getFactory().getDialect();
    final RowSelection selection = queryParameters.getRowSelection();
    final boolean useLimit = LimitHelper.useLimit(limitHandler, selection);
    final boolean hasFirstRow = LimitHelper.hasFirstRow(selection);
    final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
    final boolean callable = queryParameters.isCallable();
    final ScrollMode scrollMode = getScrollMode(scroll, hasFirstRow, useLimitOffset, queryParameters);
    PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareQueryStatement(sql, callable, scrollMode);
    try {
        int col = 1;
        //TODO: can we limit stored procedures ?!
        col += limitHandler.bindLimitParametersAtStartOfQuery(selection, st, col);
        if (callable) {
            col = dialect.registerResultSetOutParameter((CallableStatement) st, col);
        }
        col += bindParameterValues(st, queryParameters, col, session);
        col += limitHandler.bindLimitParametersAtEndOfQuery(selection, st, col);
        limitHandler.setMaxRows(selection, st);
        if (selection != null) {
            if (selection.getTimeout() != null) {
                st.setQueryTimeout(selection.getTimeout());
            }
            if (selection.getFetchSize() != null) {
                st.setFetchSize(selection.getFetchSize());
            }
        }
        // handle lock timeout...
        LockOptions lockOptions = queryParameters.getLockOptions();
        if (lockOptions != null) {
            if (lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER) {
                if (!dialect.supportsLockTimeouts()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debugf("Lock timeout [%s] requested but dialect reported to not support lock timeouts", lockOptions.getTimeOut());
                    }
                } else if (dialect.isLockTimeoutParameterized()) {
                    st.setInt(col++, lockOptions.getTimeOut());
                }
            }
        }
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Bound [{0}] parameters total", col);
        }
    } catch (SQLException | HibernateException e) {
        session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
        session.getJdbcCoordinator().afterStatementExecution();
        throw e;
    }
    return st;
}
Also used : ScrollMode(org.hibernate.ScrollMode) LockOptions(org.hibernate.LockOptions) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException) CallableStatement(java.sql.CallableStatement) Dialect(org.hibernate.dialect.Dialect) PreparedStatement(java.sql.PreparedStatement) RowSelection(org.hibernate.engine.spi.RowSelection)

Example 60 with HibernateException

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

the class CriteriaQueryTranslator method getColumnsUsingProjection.

/**
	 * Get the names of the columns constrained
	 * by this criterion.
	 */
@Override
public String[] getColumnsUsingProjection(Criteria subcriteria, String propertyName) throws HibernateException {
    //first look for a reference to a projection alias
    final Projection projection = rootCriteria.getProjection();
    String[] projectionColumns = null;
    if (projection != null) {
        projectionColumns = (projection instanceof EnhancedProjection ? ((EnhancedProjection) projection).getColumnAliases(propertyName, 0, rootCriteria, this) : projection.getColumnAliases(propertyName, 0));
    }
    if (projectionColumns == null) {
        //look for a property
        try {
            return getColumns(propertyName, subcriteria);
        } catch (HibernateException he) {
            //not found in inner query , try the outer query
            if (outerQueryTranslator != null) {
                return outerQueryTranslator.getColumnsUsingProjection(subcriteria, propertyName);
            } else {
                throw he;
            }
        }
    } else {
        //it refers to an alias of a projection
        return projectionColumns;
    }
}
Also used : HibernateException(org.hibernate.HibernateException) EnhancedProjection(org.hibernate.criterion.EnhancedProjection) Projection(org.hibernate.criterion.Projection) EnhancedProjection(org.hibernate.criterion.EnhancedProjection)

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