use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method getEntityPersisterForName.
private Queryable getEntityPersisterForName(String name) throws QueryException {
String type = getType(name);
Queryable persister = getEntityPersister(type);
if (persister == null) {
throw new QueryException("persistent class not found: " + type);
}
return persister;
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method getPropertyMapping.
PropertyMapping getPropertyMapping(String name) throws QueryException {
PropertyMapping decorator = getDecoratedPropertyMapping(name);
if (decorator != null) {
return decorator;
}
String type = getType(name);
if (type == null) {
String role = getRole(name);
if (role == null) {
throw new QueryException("alias not found: " + name);
}
//.getElementPropertyMapping();
return getCollectionPersister(role);
} else {
Queryable persister = getEntityPersister(type);
if (persister == null) {
throw new QueryException("persistent class not found: " + type);
}
return persister;
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method addFromAssociation.
/**
* Used for collection filters
*/
private void addFromAssociation(final String elementName, final String collectionRole) throws QueryException {
//q.addCollection(collectionName, collectionRole);
QueryableCollection persister = getCollectionPersister(collectionRole);
Type collectionElementType = persister.getElementType();
if (!collectionElementType.isEntityType()) {
throw new QueryException("collection of values in filter: " + elementName);
}
String[] keyColumnNames = persister.getKeyColumnNames();
//if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole);
String collectionName;
JoinSequence join = new JoinSequence(getFactory());
collectionName = persister.isOneToMany() ? elementName : createNameForCollection(collectionRole);
join.setRoot(persister, collectionName);
if (!persister.isOneToMany()) {
//many-to-many
addCollection(collectionName, collectionRole);
try {
join.addJoin((AssociationType) persister.getElementType(), elementName, JoinType.INNER_JOIN, persister.getElementColumnNames(collectionName));
} catch (MappingException me) {
throw new QueryException(me);
}
}
join.addCondition(collectionName, keyColumnNames, " = ?");
//if ( persister.hasWhere() ) join.addCondition( persister.getSQLWhereString(collectionName) );
EntityType elemType = (EntityType) collectionElementType;
addFrom(elementName, elemType.getAssociatedEntityName(), join);
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class SelectParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
String lctoken = token.toLowerCase(Locale.ROOT);
if (first) {
first = false;
if ("distinct".equals(lctoken)) {
q.setDistinct(true);
return;
} else if ("all".equals(lctoken)) {
q.setDistinct(false);
return;
}
}
if (afterNew) {
afterNew = false;
try {
holderClass = q.getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(QuerySplitter.getImportedClass(token, q.getFactory()));
} catch (ClassLoadingException e) {
throw new QueryException(e);
}
if (holderClass == null) {
throw new QueryException("class not found: " + token);
}
q.setHolderClass(holderClass);
insideNew = true;
} else if (token.equals(",")) {
if (!aggregate && ready) {
throw new QueryException("alias or expression expected in SELECT");
}
q.appendScalarSelectToken(", ");
ready = true;
} else if ("new".equals(lctoken)) {
afterNew = true;
ready = false;
} else if ("(".equals(token)) {
if (insideNew && !aggregate && !ready) {
//opening paren in new Foo ( ... )
ready = true;
} else if (aggregate) {
q.appendScalarSelectToken(token);
} else {
throw new QueryException("aggregate function expected beforeQuery ( in SELECT");
}
ready = true;
} else if (")".equals(token)) {
if (insideNew && !aggregate && !ready) {
//if we are inside a new Result(), but not inside a nested function
insideNew = false;
} else if (aggregate && ready) {
q.appendScalarSelectToken(token);
aggregateFuncTokenList.removeLast();
if (aggregateFuncTokenList.size() < 1) {
aggregate = false;
ready = false;
}
} else {
throw new QueryException("( expected beforeQuery ) in select");
}
} else if (COUNT_MODIFIERS.contains(lctoken)) {
if (!ready || !aggregate) {
throw new QueryException(token + " only allowed inside aggregate function in SELECT");
}
q.appendScalarSelectToken(token);
if ("*".equals(token)) {
// special case
q.addSelectScalar(getFunction("count", q).getReturnType(StandardBasicTypes.LONG, q.getFactory()));
}
} else if (getFunction(lctoken, q) != null && token.equals(q.unalias(token))) {
// the name of an SQL function
if (!ready) {
throw new QueryException(", expected beforeQuery aggregate function in SELECT: " + token);
}
aggregate = true;
aggregateAddSelectScalar = true;
aggregateFuncTokenList.add(lctoken);
ready = false;
q.appendScalarSelectToken(token);
if (!aggregateHasArgs(lctoken, q)) {
q.addSelectScalar(aggregateType(aggregateFuncTokenList, null, q));
if (!aggregateFuncNoArgsHasParenthesis(lctoken, q)) {
aggregateFuncTokenList.removeLast();
if (aggregateFuncTokenList.size() < 1) {
aggregate = false;
ready = false;
} else {
ready = true;
}
}
}
} else if (aggregate) {
boolean constantToken = false;
if (!ready) {
throw new QueryException("( expected afterQuery aggregate function in SELECT");
}
try {
ParserHelper.parse(aggregatePathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q);
} catch (QueryException qex) {
constantToken = true;
}
if (constantToken) {
q.appendScalarSelectToken(token);
} else {
if (aggregatePathExpressionParser.isCollectionValued()) {
q.addCollection(aggregatePathExpressionParser.getCollectionName(), aggregatePathExpressionParser.getCollectionRole());
}
q.appendScalarSelectToken(aggregatePathExpressionParser.getWhereColumn());
if (aggregateAddSelectScalar) {
q.addSelectScalar(aggregateType(aggregateFuncTokenList, aggregatePathExpressionParser.getWhereColumnType(), q));
aggregateAddSelectScalar = false;
}
aggregatePathExpressionParser.addAssociation(q);
}
} else {
if (!ready) {
throw new QueryException(", expected in SELECT");
}
ParserHelper.parse(pathExpressionParser, q.unalias(token), ParserHelper.PATH_SEPARATORS, q);
if (pathExpressionParser.isCollectionValued()) {
q.addCollection(pathExpressionParser.getCollectionName(), pathExpressionParser.getCollectionRole());
} else if (pathExpressionParser.getWhereColumnType().isEntityType()) {
q.addSelectClass(pathExpressionParser.getSelectName());
}
q.appendScalarSelectTokens(pathExpressionParser.getWhereColumns());
q.addSelectScalar(pathExpressionParser.getWhereColumnType());
pathExpressionParser.addAssociation(q);
ready = false;
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class WhereParser method getElementName.
private String getElementName(PathExpressionParser.CollectionElement element, QueryTranslatorImpl q) throws QueryException {
String name;
if (element.isOneToMany) {
name = element.alias;
} else {
Type type = element.elementType;
if (type.isEntityType()) {
//ie. a many-to-many
String entityName = ((EntityType) type).getAssociatedEntityName();
name = pathExpressionParser.continueFromManyToMany(entityName, element.elementColumns, q);
} else {
throw new QueryException("illegally dereferenced collection element");
}
}
return name;
}
Aggregations