use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class FromElementType method applyTreatAsDeclarations.
public void applyTreatAsDeclarations(Set<String> treatAsDeclarations) {
if (treatAsDeclarations != null && !treatAsDeclarations.isEmpty()) {
if (this.treatAsDeclarations == null) {
this.treatAsDeclarations = new HashSet<String>();
}
for (String treatAsSubclassName : treatAsDeclarations) {
try {
EntityPersister subclassPersister = fromElement.getSessionFactoryHelper().requireClassPersister(treatAsSubclassName);
this.treatAsDeclarations.add(subclassPersister.getEntityName());
} catch (SemanticException e) {
throw new QueryException("Unable to locate persister for subclass named in TREAT-AS : " + treatAsSubclassName);
}
}
if (joinSequence != null) {
joinSequence.applyTreatAsDeclarations(this.treatAsDeclarations);
}
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class FromElementType method getCollectionPropertyReference.
public CollectionPropertyReference getCollectionPropertyReference(final String propertyName) {
if (queryableCollection == null) {
throw new QueryException("Not a collection reference");
}
final PropertyMapping collectionPropertyMapping;
if (queryableCollection.isManyToMany() && queryableCollection.hasIndex() && SPECIAL_MANY2MANY_TREATMENT_FUNCTION_NAMES.contains(propertyName)) {
collectionPropertyMapping = new SpecialManyToManyCollectionPropertyMapping();
} else if (CollectionProperties.isCollectionProperty(propertyName)) {
if (this.collectionPropertyMapping == null) {
this.collectionPropertyMapping = new CollectionPropertyMapping(queryableCollection);
}
collectionPropertyMapping = this.collectionPropertyMapping;
} else {
collectionPropertyMapping = queryableCollection;
}
return new CollectionPropertyReference() {
@Override
public Type getType() {
return collectionPropertyMapping.toType(propertyName);
}
@Override
public String[] toColumns(final String tableAlias) {
if (propertyName.equalsIgnoreCase("index")) {
return collectionPropertyMapping.toColumns(tableAlias, propertyName);
}
Map enabledFilters = fromElement.getWalker().getEnabledFilters();
String subquery = CollectionSubqueryFactory.createCollectionSubquery(joinSequence.copy().setUseThetaStyle(true), enabledFilters, collectionPropertyMapping.toColumns(tableAlias, propertyName));
LOG.debugf("toColumns(%s,%s) : subquery = %s", tableAlias, propertyName, subquery);
return new String[] { "(" + subquery + ")" };
}
};
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class IdentNode method resolveAsNakedComponentPropertyRefLHS.
private boolean resolveAsNakedComponentPropertyRefLHS(DotNode parent) {
FromElement fromElement = locateSingleFromElement();
if (fromElement == null) {
return false;
}
Type componentType = getNakedPropertyType(fromElement);
if (componentType == null) {
throw new QueryException("Unable to resolve path [" + parent.getPath() + "], unexpected token [" + getOriginalText() + "]");
}
if (!componentType.isComponentType()) {
throw new QueryException("Property '" + getOriginalText() + "' is not a component. Use an alias to reference associations or collections.");
}
Type propertyType;
String propertyPath = getText() + "." + getNextSibling().getText();
try {
// check to see if our "propPath" actually
// represents a property on the persister
propertyType = fromElement.getPropertyType(getText(), propertyPath);
} catch (Throwable t) {
// assume we do *not* refer to a property on the given persister
return false;
}
setFromElement(fromElement);
parent.setPropertyPath(propertyPath);
parent.setDataType(propertyType);
return true;
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class CastFunctionNode method resolve.
/**
* Called from the hql-sql grammar afterQuery the children of the CAST have been resolved.
*
* @param inSelect Is this call part of the SELECT clause?
*/
public void resolve(boolean inSelect) {
this.dialectCastFunction = getSessionFactoryHelper().findSQLFunction("cast");
if (dialectCastFunction == null) {
dialectCastFunction = CastFunction.INSTANCE;
}
this.expressionNode = (Node) getFirstChild();
if (expressionNode == null) {
throw new QueryException("Could not resolve expression to CAST");
}
if (SqlNode.class.isInstance(expressionNode)) {
final Type expressionType = ((SqlNode) expressionNode).getDataType();
if (expressionType != null) {
if (expressionType.isEntityType()) {
throw new QueryException("Expression to CAST cannot be an entity : " + expressionNode.getText());
}
if (expressionType.isComponentType()) {
throw new QueryException("Expression to CAST cannot be a composite : " + expressionNode.getText());
}
if (expressionType.isCollectionType()) {
throw new QueryException("Expression to CAST cannot be a collection : " + expressionNode.getText());
}
}
}
this.typeNode = (IdentNode) expressionNode.getNextSibling();
if (typeNode == null) {
throw new QueryException("Could not resolve requested type for CAST");
}
final String typeName = typeNode.getText();
this.castType = getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType(typeName);
if (castType == null) {
throw new QueryException("Could not resolve requested type for CAST : " + typeName);
}
if (castType.isEntityType()) {
throw new QueryException("CAST target type cannot be an entity : " + expressionNode.getText());
}
if (castType.isComponentType()) {
throw new QueryException("CAST target type cannot be a composite : " + expressionNode.getText());
}
if (castType.isCollectionType()) {
throw new QueryException("CAST target type cannot be a collection : " + expressionNode.getText());
}
setDataType(castType);
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class PathExpressionParser method token.
public void token(String token, QueryTranslatorImpl q) throws QueryException {
if (token != null) {
path.append(token);
}
String alias = q.getPathAlias(path.toString());
if (alias != null) {
//reset the dotcount (but not the path)
reset(q);
//afterQuery reset!
currentName = alias;
currentPropertyMapping = q.getPropertyMapping(currentName);
if (!ignoreInitialJoin) {
JoinSequence ojf = q.getPathJoin(path.toString());
try {
//afterQuery reset!
joinSequence.addCondition(ojf.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
} catch (MappingException me) {
throw new QueryException(me);
}
// we don't need to worry about any condition in the ON clause
// here (toFromFragmentString), since anything in the ON condition
// is already applied to the whole query
}
} else if (".".equals(token)) {
dotcount++;
} else {
if (dotcount == 0) {
if (!continuation) {
if (!q.isName(token)) {
throw new QueryException("undefined alias: " + token);
}
currentName = token;
currentPropertyMapping = q.getPropertyMapping(currentName);
}
} else if (dotcount == 1) {
if (currentName != null) {
currentProperty = token;
} else if (collectionName != null) {
//processCollectionProperty(token, q.getCollectionPersister(collectionRole), collectionName);
continuation = false;
} else {
throw new QueryException("unexpected");
}
} else {
// dotcount>=2
// Do the corresponding RHS
Type propertyType = getPropertyType();
if (propertyType == null) {
throw new QueryException("unresolved property: " + path);
}
if (propertyType.isComponentType()) {
dereferenceComponent(token);
} else if (propertyType.isEntityType()) {
if (!isCollectionValued()) {
dereferenceEntity(token, (EntityType) propertyType, q);
}
} else if (propertyType.isCollectionType()) {
dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);
} else {
if (token != null) {
throw new QueryException("dereferenced: " + path);
}
}
}
}
}
Aggregations