The specification needs clarification when it comes to downcasting within the query filter. Currently, the JDO 3.0 specification states (14.6.2):
"Navigation through a null-valued field, which would throw NullPointerException, is treated as if the subexpression returned false. Similarly, a failed cast operation, which would throw ClassCastException, is treated as if the subexpression returned false. Other subexpressions or other values for variables might still qualify the candidate instance for inclusion in the result set."
The clarification is that if a cast will never be successful (casting Employee as Integer, for example), then an exception should be thrown (JDOUserException with an inner ClassCastException?), otherwise, the cast behaves as the specification dictates.