use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class FromElement method buildTypeDiscriminatorMetadata.
private TypeDiscriminatorMetadata buildTypeDiscriminatorMetadata() {
final String aliasToUse = getTableAlias();
Queryable queryable = getQueryable();
if (queryable == null) {
QueryableCollection collection = getQueryableCollection();
if (!collection.getElementType().isEntityType()) {
throw new QueryException("type discrimination cannot be applied to value collection [" + collection.getRole() + "]");
}
queryable = (Queryable) collection.getElementPersister();
}
handlePropertyBeingDereferenced(getDataType(), DISCRIMINATOR_PROPERTY_NAME);
return new TypeDiscriminatorMetadataImpl(queryable.getTypeDiscriminatorMetadata(), aliasToUse);
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class IntoClause method validateTypes.
public void validateTypes(SelectClause selectClause) throws QueryException {
Type[] selectTypes = selectClause.getQueryReturnTypes();
if (selectTypes.length + selectClause.getTotalParameterCount() != types.length) {
throw new QueryException("number of select types did not match those for insert");
}
int parameterCount = 0;
for (int i = 0; i < types.length; i++) {
if (selectClause.getParameterPositions().contains(i)) {
parameterCount++;
} else if (!areCompatible(types[i], selectTypes[i - parameterCount])) {
throw new QueryException("insertion type [" + types[i] + "] and selection type [" + selectTypes[i - parameterCount] + "] at position " + i + " are not compatible");
}
}
// otherwise, everything ok.
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class JavaConstantNode method getRenderText.
@Override
@SuppressWarnings("unchecked")
public String getRenderText(SessionFactoryImplementor sessionFactory) {
final Type type = expectedType == null ? heuristicType : Number.class.isAssignableFrom(heuristicType.getReturnedClass()) ? heuristicType : expectedType;
try {
if (LiteralType.class.isInstance(type)) {
final LiteralType literalType = (LiteralType) type;
final Dialect dialect = factory.getDialect();
return literalType.objectToSQLString(constantValue, dialect);
} else if (AttributeConverterTypeAdapter.class.isInstance(type)) {
final AttributeConverterTypeAdapter converterType = (AttributeConverterTypeAdapter) type;
if (!converterType.getModelType().isInstance(constantValue)) {
throw new QueryException(String.format(Locale.ENGLISH, "Recognized query constant expression [%s] was not resolved to type [%s] expected by defined AttributeConverter [%s]", constantExpression, constantValue.getClass().getName(), converterType.getModelType().getName()));
}
final Object value = converterType.getAttributeConverter().convertToDatabaseColumn(constantValue);
if (String.class.equals(converterType.getJdbcType())) {
return "'" + value + "'";
} else {
return value.toString();
}
} else {
throw new QueryException(String.format(Locale.ENGLISH, "Unrecognized Hibernate Type for handling query constant (%s); expecting LiteralType implementation or AttributeConverter", constantExpression));
}
} catch (QueryException e) {
throw e;
} catch (Exception t) {
throw new QueryException(QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t);
}
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class HqlSqlWalker method isNonQualifiedPropertyRef.
@Override
protected boolean isNonQualifiedPropertyRef(AST ident) {
final String identText = ident.getText();
if (currentFromClause.isFromElementAlias(identText)) {
return false;
}
List fromElements = currentFromClause.getExplicitFromElements();
if (fromElements.size() == 1) {
final FromElement fromElement = (FromElement) fromElements.get(0);
try {
LOG.tracev("Attempting to resolve property [{0}] as a non-qualified ref", identText);
return fromElement.getPropertyMapping(identText).toType(identText) != null;
} catch (QueryException e) {
// Should mean that no such property was found
}
}
return false;
}
use of org.hibernate.QueryException in project hibernate-orm by hibernate.
the class AssignmentSpecification method getSqlAssignmentFragment.
public String getSqlAssignmentFragment() {
if (sqlAssignmentString == null) {
try {
SqlGenerator sqlGenerator = new SqlGenerator(factory);
sqlGenerator.comparisonExpr(eq, false);
// false indicates to not generate parens around the assignment
sqlAssignmentString = sqlGenerator.getSQL();
} catch (Throwable t) {
throw new QueryException("cannot interpret set-clause assignment");
}
}
return sqlAssignmentString;
}
Aggregations