use of org.hibernate.metamodel.model.domain.DomainType in project hibernate-orm by hibernate.
the class AbstractSelectionQuery method verifyResultType.
protected static <T> void verifyResultType(Class<T> resultClass, SqmExpressible<?> sqmExpressible, SessionFactoryImplementor sessionFactory) {
assert sqmExpressible != null;
final JavaType<?> expressibleJavaType = sqmExpressible.getExpressibleJavaType();
assert expressibleJavaType != null;
final Class<?> javaTypeClass = expressibleJavaType.getJavaTypeClass();
if (!resultClass.isAssignableFrom(javaTypeClass)) {
if (expressibleJavaType instanceof PrimitiveJavaType) {
if (((PrimitiveJavaType) expressibleJavaType).getPrimitiveClass() == resultClass) {
return;
}
throwQueryTypeMismatchException(resultClass, sqmExpressible);
}
// But the expected resultClass could be a subtype of that, so we need to check the JdbcType
if (javaTypeClass == Date.class) {
JdbcType jdbcType = null;
if (sqmExpressible instanceof BasicDomainType<?>) {
jdbcType = ((BasicDomainType<?>) sqmExpressible).getJdbcType();
} else if (sqmExpressible instanceof SqmPathSource<?>) {
final DomainType<?> domainType = ((SqmPathSource<?>) sqmExpressible).getSqmPathType();
if (domainType instanceof BasicDomainType<?>) {
jdbcType = ((BasicDomainType<?>) domainType).getJdbcType();
}
}
if (jdbcType != null) {
switch(jdbcType.getJdbcTypeCode()) {
case Types.DATE:
if (resultClass.isAssignableFrom(java.sql.Date.class)) {
return;
}
break;
case Types.TIME:
if (resultClass.isAssignableFrom(java.sql.Time.class)) {
return;
}
break;
case Types.TIMESTAMP:
if (resultClass.isAssignableFrom(java.sql.Timestamp.class)) {
return;
}
break;
}
}
}
throwQueryTypeMismatchException(resultClass, sqmExpressible);
}
}
Aggregations