DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Key: NUCJPA-235
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Andy Jefferson
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Support JPA 2.1 JPQL "TREAT" in WHERE clause

Created: 28/May/13 08:43 AM   Updated: 10/Dec/13 10:24 AM   Resolved: 04/Dec/13 02:47 PM
Component/s: API
Affects Version/s: None
Fix Version/s: 3.3.5

 Description  « Hide
4.4.9 Downcasting
The use of the TREAT operator is supported for downcasting within path expressions in the FROM and WHERE clauses. Use of the TREAT operator allows access to subclass-specific state.

WHERE Clause
If during query execution the first argument to the TREAT operator is not a subtype (proper or improper) of the target type, the path is considered to have no value, and does not participate in the determination of the result. That is, in the case of a join, the referenced object does not participate in the result, and in the case of a restriction, the associated predicate is false. Use of the TREAT operator therefore also has the effect of filtering on the specified type (and its subtypes) as well as performing the downcast. If the target type is not a subtype (proper or improper) of the static type of the first argument, the query is invalid.

SELECT e FROM Employee e JOIN e.projects p
WHERE TREAT(p AS LargeProject).budget > 1000
TREAT(p AS SmallProject).name LIKE 'Persist%'
p.description LIKE "cost overrun"

SELECT e FROM Employee e
WHERE TREAT(e AS Exempt).vacationDays > 10
OR TREAT(e AS Contractor).hours > 100

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 04/Dec/13 02:47 PM
SVN trunk supports JPQL "TREAT" in WHERE clause. Not tried in FROM clause but most logical usage is in WHERE IMHO. If anyone wants FROM clause support then write tests and implement any additions that are needed