jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: query improvements: downcasting

From: Matthew Adams <matthew_at_matthewadams.me>
Date: Mon, 7 Mar 2011 15:48:40 -0600

Responses inline...

> SQL supports this via the TREAT ... AS operator:
>    TREAT (expression AS datatype)
> where datatype is a subtype of the static type of the expression.
>
ok

> An open issue however is the handling of the case where the
> instance passed to TREAT is not of the same type or a subtype of the
> specified datatype.
>
> Databases seem to differ as to whether the result should be null or
> whether an error is raised.   We need to decide this as well.
>
It seems appropriate to me that in the event that the downcast is
invalid, it should cause all query conditions involving the identifier
that is being downcast to evaluate to false. I don't think an error
should be raised. This would also prevent our having to worry about
attempting to return results whose specification includes instances or
reachable properties of instances of the downcast type (as in your
first example).

> The Criteria API already provides the Expression method
>    <X> Expression<X> as(Class<X> type);
>
Same semantics as the string query form, IMHO.

-matthew

-- 
mailto:matthew_at_matthewadams.me
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12_at_gmail.com
msn:matthew_at_matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams