use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method verifyParametersBound.
public void verifyParametersBound(boolean reserveFirstParameter) {
// verify named parameters bound
for (Map.Entry<QueryParameter, QueryParameterBinding> bindEntry : parameterBindingMap.entrySet()) {
if (!bindEntry.getValue().isBound()) {
if (bindEntry.getKey().getName() != null) {
throw new QueryException("Named parameter [" + bindEntry.getKey().getName() + "] not set");
} else {
throw new QueryException("Parameter memento [" + bindEntry.getKey() + "] not set");
}
}
}
// verify position parameters bound
int startIndex = 0;
if (!parameterMetadata.isOrdinalParametersZeroBased()) {
startIndex = 1;
}
for (int i = startIndex; i < positionalParameterBindings.size(); i++) {
QueryParameterBinding binding = null;
if (parameterMetadata.isOrdinalParametersZeroBased()) {
binding = positionalParameterBindings.get(i);
} else {
binding = positionalParameterBindings.get(i - 1);
}
if (binding == null || !binding.isBound()) {
throw new QueryException("Positional parameter [" + i + "] not set");
}
}
// verify position parameter count is correct
final int positionalValueSpan = calculatePositionalValueSpan(reserveFirstParameter);
final int positionCounts = parameterMetadata.getPositionalParameterCount();
if (positionCounts != positionalValueSpan) {
if (reserveFirstParameter && positionCounts - 1 != positionalValueSpan) {
throw new QueryException("Expected positional parameter count: " + (positionCounts - 1) + ", actually detected " + positionalValueSpan);
} else if (!reserveFirstParameter) {
throw new QueryException("Expected positional parameter count: " + (positionCounts) + ", actually detected " + positionalValueSpan);
}
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testFetchInSubqueryFails.
@Test
public void testFetchInSubqueryFails() {
Session s = openSession();
try {
s.createQuery("from Animal a where a.mother in (select m from Animal a1 inner join a1.mother as m join fetch m.mother)").list();
fail("fetch join allowed in subquery");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException expected) {
// expected behavior
}
s.close();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testInvalidCollectionDereferencesFail.
@Test
public void testInvalidCollectionDereferencesFail() {
Session s = openSession();
s.beginTransaction();
// control group...
s.createQuery("from Animal a join a.offspring o where o.description = 'xyz'").list();
s.createQuery("from Animal a join a.offspring o where o.father.description = 'xyz'").list();
s.createQuery("from Animal a join a.offspring o order by o.description").list();
s.createQuery("from Animal a join a.offspring o order by o.father.description").list();
try {
s.createQuery("from Animal a where a.offspring.description = 'xyz'").list();
fail("illegal collection dereference semantic did not cause failure");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException qe) {
log.trace("expected failure...", qe);
}
try {
s.createQuery("from Animal a where a.offspring.father.description = 'xyz'").list();
fail("illegal collection dereference semantic did not cause failure");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException qe) {
log.trace("expected failure...", qe);
}
try {
s.createQuery("from Animal a order by a.offspring.description").list();
fail("illegal collection dereference semantic did not cause failure");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException qe) {
log.trace("expected failure...", qe);
}
try {
s.createQuery("from Animal a order by a.offspring.father.description").list();
fail("illegal collection dereference semantic did not cause failure");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException qe) {
log.trace("expected failure...", qe);
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class BulkManipulationTest method testSelectWithNamedParamProjection.
@Test
public void testSelectWithNamedParamProjection() {
Session s = openSession();
try {
s.createQuery("select :someParameter, id from Car");
fail("Should throw an unsupported exception");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException q) {
// allright
} finally {
s.close();
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class BulkManipulationTest method testInsertIntoSuperclassPropertiesFails.
@Test
public void testInsertIntoSuperclassPropertiesFails() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction t = s.beginTransaction();
try {
s.createQuery("insert into Human (id, bodyWeight) select id, bodyWeight from Lizard").executeUpdate();
fail("superclass prop insertion did not error");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException e) {
// expected result
}
t.commit();
t = s.beginTransaction();
s.createQuery("delete Animal where mother is not null").executeUpdate();
s.createQuery("delete Animal where father is not null").executeUpdate();
s.createQuery("delete Animal").executeUpdate();
t.commit();
s.close();
data.cleanup();
}
Aggregations