use of org.hibernate.sql.ast.SqlTreeCreationException in project hibernate-orm by hibernate.
the class SqmUtil method createValueBindings.
private static void createValueBindings(JdbcParameterBindings jdbcParameterBindings, QueryParameterImplementor<?> domainParam, QueryParameterBinding<?> domainParamBinding, Bindable parameterType, List<JdbcParameter> jdbcParams, Object bindValue, Function<NavigablePath, TableGroup> tableGroupLocator, SharedSessionContractImplementor session) {
if (parameterType == null) {
throw new SqlTreeCreationException("Unable to interpret mapping-model type for Query parameter : " + domainParam);
}
if (parameterType instanceof EntityIdentifierMapping) {
final EntityIdentifierMapping identifierMapping = (EntityIdentifierMapping) parameterType;
final EntityMappingType entityMapping = identifierMapping.findContainingEntityMapping();
if (entityMapping.getRepresentationStrategy().getInstantiator().isInstance(bindValue, session.getFactory())) {
bindValue = identifierMapping.getIdentifier(bindValue);
}
} else if (parameterType instanceof EntityMappingType) {
final EntityIdentifierMapping identifierMapping = ((EntityMappingType) parameterType).getIdentifierMapping();
final EntityMappingType entityMapping = identifierMapping.findContainingEntityMapping();
parameterType = identifierMapping;
if (entityMapping.getRepresentationStrategy().getInstantiator().isInstance(bindValue, session.getFactory())) {
bindValue = identifierMapping.getIdentifier(bindValue);
}
} else if (parameterType instanceof EntityAssociationMapping) {
EntityAssociationMapping association = (EntityAssociationMapping) parameterType;
bindValue = association.getForeignKeyDescriptor().getAssociationKeyFromSide(bindValue, association.getSideNature().inverse(), session);
parameterType = association.getForeignKeyDescriptor();
} else if (parameterType instanceof PluralAttributeMapping) {
// for now, let's blow up and see where this happens and fix the specifics...
throw new NotYetImplementedFor6Exception("Binding parameters whose inferred type comes from plural attribute not yet implemented");
}
int offset = jdbcParameterBindings.registerParametersForEachJdbcValue(bindValue, Clause.IRRELEVANT, parameterType, jdbcParams, session);
assert offset == jdbcParams.size();
}
use of org.hibernate.sql.ast.SqlTreeCreationException in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method prepareReusablePath.
private TableGroup prepareReusablePath(FromClauseIndex fromClauseIndex, JpaPath<?> sqmPath, Consumer<TableGroup> implicitJoinChecker) {
final JpaPath<?> parentPath;
if (sqmPath instanceof SqmTreatedPath<?, ?>) {
parentPath = ((SqmTreatedPath<?, ?>) sqmPath).getWrappedPath();
} else {
parentPath = sqmPath.getParentPath();
}
if (parentPath == null) {
return null;
}
final TableGroup tableGroup = fromClauseIndex.findTableGroup(parentPath.getNavigablePath());
if (tableGroup == null) {
final TableGroup parentTableGroup = prepareReusablePath(fromClauseIndex, parentPath, implicitJoinChecker);
if (parentTableGroup == null) {
final TableGroup parent = fromClauseIndex.findTableGroupOnParents(parentPath.getNavigablePath());
if (parent != null) {
throw new SqlTreeCreationException("Found un-correlated path usage in sub query - " + parentPath);
}
throw new SqlTreeCreationException("Could not locate TableGroup - " + parentPath.getNavigablePath());
}
if (parentPath instanceof SqmTreatedPath<?, ?>) {
fromClauseIndex.register((SqmPath<?>) parentPath, parentTableGroup);
return parentTableGroup;
}
final TableGroup newTableGroup = createTableGroup(parentTableGroup, (SqmPath<?>) parentPath);
if (newTableGroup != null) {
implicitJoinChecker.accept(newTableGroup);
if (sqmPath instanceof SqmFrom<?, ?>) {
registerTreatUsage((SqmFrom<?, ?>) sqmPath, newTableGroup);
}
}
return newTableGroup;
} else if (sqmPath instanceof SqmTreatedPath<?, ?>) {
fromClauseIndex.register((SqmPath<?>) sqmPath, tableGroup);
if (sqmPath instanceof SqmFrom<?, ?>) {
registerTreatUsage((SqmFrom<?, ?>) sqmPath, tableGroup);
}
} else if (parentPath instanceof SqmFrom<?, ?>) {
registerTreatUsage((SqmFrom<?, ?>) parentPath, tableGroup);
}
return tableGroup;
}
Aggregations