use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class BulkManipulationTest method testSimpleInsertTypeMismatchException.
@Test
public void testSimpleInsertTypeMismatchException() {
Session s = openSession();
try {
org.hibernate.Query q = s.createQuery("insert into Pickup (id, owner, vin) select id, :owner, id from Car");
fail("Parameter type mismatch but no exception thrown");
} catch (Throwable throwable) {
QueryException queryException = assertTyping(QueryException.class, throwable.getCause());
String m = queryException.getMessage();
// insertion type [org.hibernate.type.StringType@21e3cc77] and selection type [org.hibernate.type.LongType@7284aa02] at position 2 are not compatible [insert into Pickup (id, owner, vin) select id, :owner, id from org.hibernate.test.hql.Car]
int st = m.indexOf("org.hibernate.type.StringType");
int lt = m.indexOf("org.hibernate.type.LongType");
assertTrue("type causing error not reported", st > -1);
assertTrue("type causing error not reported", lt > -1);
assertTrue(lt > st);
assertTrue("wrong position of type error reported", m.indexOf("position 2") > -1);
} finally {
s.close();
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class CaseStatementTest method testSimpleCaseStatementWithParamAllResults.
@Test
public void testSimpleCaseStatementWithParamAllResults() {
Session s = openSession();
Transaction t = s.beginTransaction();
try {
s.createQuery("select case p.name when 'Steve' then :opt1 else :opt2 end from Person p").setString("opt1", "x").setString("opt2", "y").list();
fail("was expecting an exception");
} catch (IllegalArgumentException e) {
assertTyping(QueryException.class, e.getCause());
} catch (QueryException expected) {
// expected
}
s.createQuery("select case p.name when 'Steve' then cast( :opt1 as string ) else cast( :opt2 as string) end from Person p").setString("opt1", "x").setString("opt2", "y").list();
t.commit();
s.close();
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class HQLTest method prepareTest.
@Override
protected void prepareTest() throws Exception {
super.prepareTest();
SelectClause.VERSION2_SQL = true;
DotNode.regressionStyleJoinSuppression = true;
DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = new DotNode.IllegalCollectionDereferenceExceptionBuilder() {
public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
throw new QueryException("illegal syntax near collection: " + propertyName);
}
};
SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = true;
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class PathExpressionParser method prepareForIndex.
private void prepareForIndex(QueryTranslatorImpl q) throws QueryException {
QueryableCollection collPersister = q.getCollectionPersister(collectionRole);
if (!collPersister.hasIndex()) {
throw new QueryException("unindexed collection beforeQuery []: " + path);
}
String[] indexCols = collPersister.getIndexColumnNames();
if (indexCols.length != 1) {
throw new QueryException("composite-index appears in []: " + path);
}
//String[] keyCols = collPersister.getKeyColumnNames();
JoinSequence fromJoins = new JoinSequence(q.getFactory()).setUseThetaStyle(useThetaStyleJoin).setRoot(collPersister, collectionName).setNext(joinSequence.copy());
if (!continuation) {
addJoin(collectionName, collPersister.getCollectionType());
}
//TODO: get SQL rendering out of here
joinSequence.addCondition(collectionName + '.' + indexCols[0] + " = ");
CollectionElement elem = new CollectionElement();
elem.elementColumns = collPersister.getElementColumnNames(collectionName);
elem.elementType = collPersister.getElementType();
elem.isOneToMany = collPersister.isOneToMany();
elem.alias = collectionName;
elem.joinSequence = joinSequence;
collectionElements.addLast(elem);
setExpectingCollectionIndex();
q.addCollection(collectionName, collectionRole);
q.addFromJoinOnly(collectionName, fromJoins);
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class PathExpressionParser method getPropertyType.
protected Type getPropertyType() throws QueryException {
String propertyPath = getPropertyPath();
Type propertyType = getPropertyMapping().toType(propertyPath);
if (propertyType == null) {
throw new QueryException("could not resolve property type: " + propertyPath);
}
return propertyType;
}
Aggregations