use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class ExceptionConverterImpl method convert.
@Override
public RuntimeException convert(HibernateException e, LockOptions lockOptions) {
Throwable cause = e;
if (cause instanceof StaleStateException) {
final PersistenceException converted = wrapStaleStateException((StaleStateException) cause);
handlePersistenceException(converted);
return converted;
} else if (cause instanceof LockingStrategyException) {
final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions);
handlePersistenceException(converted);
return converted;
} else if (cause instanceof org.hibernate.exception.LockTimeoutException) {
final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions);
handlePersistenceException(converted);
return converted;
} else if (cause instanceof org.hibernate.PessimisticLockException) {
final PersistenceException converted = wrapLockException((HibernateException) cause, lockOptions);
handlePersistenceException(converted);
return converted;
} else if (cause instanceof org.hibernate.QueryTimeoutException) {
final QueryTimeoutException converted = new QueryTimeoutException(cause.getMessage(), cause);
handlePersistenceException(converted);
return converted;
} else if (cause instanceof ObjectNotFoundException) {
final EntityNotFoundException converted = new EntityNotFoundException(cause.getMessage());
handlePersistenceException(converted);
return converted;
} else if (cause instanceof org.hibernate.NonUniqueObjectException) {
final EntityExistsException converted = new EntityExistsException(cause.getMessage());
handlePersistenceException(converted);
return converted;
} else if (cause instanceof org.hibernate.NonUniqueResultException) {
final NonUniqueResultException converted = new NonUniqueResultException(cause.getMessage());
handlePersistenceException(converted);
return converted;
} else if (cause instanceof UnresolvableObjectException) {
final EntityNotFoundException converted = new EntityNotFoundException(cause.getMessage());
handlePersistenceException(converted);
return converted;
} else if (cause instanceof QueryException) {
return new IllegalArgumentException(cause);
} else if (cause instanceof MultipleBagFetchException) {
return new IllegalArgumentException(cause);
} else if (cause instanceof TransientObjectException) {
try {
sharedSessionContract.markForRollbackOnly();
} catch (Exception ne) {
//we do not want the subsequent exception to swallow the original one
log.unableToMarkForRollbackOnTransientObjectException(ne);
}
//Spec 3.2.3 Synchronization rules
return new IllegalStateException(e);
} else {
final PersistenceException converted = new PersistenceException(cause);
handlePersistenceException(converted);
return converted;
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class StandardCallableStatementSupport method renderCallableStatement.
@Override
public String renderCallableStatement(String procedureName, ParameterStrategy parameterStrategy, List<ParameterRegistrationImplementor<?>> parameterRegistrations, SharedSessionContractImplementor session) {
final StringBuilder buffer = new StringBuilder().append("{call ").append(procedureName).append("(");
String sep = "";
for (ParameterRegistrationImplementor parameter : parameterRegistrations) {
if (parameter == null) {
throw new QueryException("Parameter registrations had gaps");
}
if (parameter.getMode() == ParameterMode.REF_CURSOR) {
verifyRefCursorSupport(session.getJdbcServices().getJdbcEnvironment().getDialect());
buffer.append(sep).append("?");
sep = ",";
} else {
for (int i = 0; i < parameter.getSqlTypes().length; i++) {
buffer.append(sep).append("?");
sep = ",";
}
}
}
return buffer.append(")}").toString();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testInvalidFetchSemantics.
@Test
public void testInvalidFetchSemantics() {
Session s = openSession();
s.beginTransaction();
try {
s.createQuery("select mother from Human a left join fetch a.mother mother").list();
fail("invalid fetch semantic allowed!");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException e) {
}
try {
s.createQuery("select mother from Human a left join fetch a.mother mother").list();
fail("invalid fetch semantic allowed!");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException e) {
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testIllegalMixedTransformerQueries.
@Test
public void testIllegalMixedTransformerQueries() {
Session session = openSession();
Transaction t = session.beginTransaction();
try {
getSelectNewQuery(session).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
fail("'select new' together with a resulttransformer should result in error!");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException he) {
assertTrue(he.getMessage().indexOf("ResultTransformer") == 0);
}
try {
getSelectNewQuery(session).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).iterate();
fail("'select new' together with a resulttransformer should result in error!");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (HibernateException he) {
assertTrue(he.getMessage().indexOf("ResultTransformer") == 0);
}
try {
getSelectNewQuery(session).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).scroll();
fail("'select new' together with a resulttransformer should result in error!");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (HibernateException he) {
assertTrue(he.getMessage().indexOf("ResultTransformer") == 0);
}
t.commit();
session.close();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class FooBarTest method testParameterCheck.
@Test
public void testParameterCheck() throws HibernateException {
Session s = openSession();
try {
Query q = s.createQuery("select bar from Bar as bar where bar.x > :myX");
q.list();
fail("Should throw QueryException for missing myX");
} catch (QueryException iae) {
// should happen
} finally {
s.close();
}
s = openSession();
try {
Query q = s.createQuery("select bar from Bar as bar where bar.x > ?");
q.list();
fail("Should throw QueryException for missing ?");
} catch (QueryException iae) {
// should happen
} finally {
s.close();
}
s = openSession();
try {
Query q = s.createQuery("select bar from Bar as bar where bar.x > ? or bar.short = 1 or bar.string = 'ff ? bb'");
q.setInteger(0, 1);
q.list();
} catch (QueryException iae) {
fail("Should not throw QueryException for missing ?");
} finally {
s.close();
}
s = openSession();
try {
Query q = s.createQuery("select bar from Bar as bar where bar.string = ' ? ' or bar.string = '?'");
q.list();
} catch (QueryException iae) {
fail("Should not throw QueryException for ? in quotes");
} finally {
s.close();
}
s = openSession();
try {
Query q = s.createQuery("select bar from Bar as bar where bar.string = ? or bar.string = ? or bar.string = ?");
q.setParameter(0, "bull");
q.setParameter(2, "shit");
q.list();
fail("should throw exception telling me i have not set parameter 1");
} catch (QueryException iae) {
// should happen!
} finally {
s.close();
}
}
Aggregations