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);
}
}
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);
}
}
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()));
}
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;
}
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;
}
}
Aggregations