Class TypecheckUtil


  • public class TypecheckUtil
    extends Object
    Functions for typechecking comparison expressions and assignments in the SQM tree. A comparison expression is any predicate like x = y or x > y. An assignment is an element of the set clause in an update query, or an element of the values list in an insert query.

    The rules here are not the same as the rules for the Java language, nor are they identical to the rules for SQL. For example:

    • In Java, a comparison expression like '1'.equals(1) is well-typed, and evaluates to false. In most SQL dialects, this expression evaluates to true, via implicit type conversions. Here we reject such comparison expressions.
    • In Java, if two classes are related by inheritance, then one is assignable to the other. But here, this assignment is only legal if the two classes are entity types belonging to the same mapped entity inheritance hierarchy.
    • On the other hand, in Java, java.sql.Date and java.time.LocalDate may not be compared nor assigned. But here they're considered inter-comparable and inter-assignable.

    Two basic types are considered comparable if they map to the same "family" of JDBC types. Here we allow some latitude so that different numeric types are comparable, and different string types are comparable. However, we do not allow comparisons between types which involve more questionable/unportable implicit type conversions (between integers and strings, for example). This means that we accept comparisons between basic types which map completely unrelated types in Java.

    Entity types have identity equality. That is, two entities are considered equal if their primary keys are equal.

    Embeddable and tuple types have value equality. That is, they're considered equal if their members are equal. For convenience, an embeddable object may be compared directly to a tuple constructor.

    Comparison of discriminators (that is, of literal entity types and type() function application) is legal only when the entity types belong to the same mapped entity hierarchy.

    See Also:
    assertComparable(Expression, Expression, SessionFactoryImplementor), assertAssignable(String, SqmPath, SqmTypedNode, SessionFactoryImplementor)