I tried the Java SE case without a constructor expression but with TYPE(e) and get the same error:
public List findAllEmployeeProjectionObjects() {
return em.createQuery(
"SELECT TYPE(e), e.id,e.name "+
"FROM Employee e "+
"ORDER BY e.name")
.getResultList();
}
Persisted examples.model.Employee[ id=158 ]
Found examples.model.Employee[ id=158 ]
Found employee: examples.model.Employee[ id=158 ]
Found employee DTO: EmployeeDTO[ id=158 ] [ name=John Doe] [ entityName=null] [ entityClass=null]
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-6093] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid Type Expression on [examples.model.Employee]. The class does not have a descriptor, or a descriptor that does not use inheritance or uses a ClassExctractor for inheritance
at org.eclipse.persistence.exceptions.QueryException.invalidTypeExpression(QueryException.java:717)
at org.eclipse.persistence.internal.expressions.ClassTypeExpression.validateNode(ClassTypeExpression.java:101)
at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:2962)
at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:342)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1311)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildReportQuerySelectStatement(ExpressionQueryMechanism.java:560)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildReportQuerySelectStatement(ExpressionQueryMechanism.java:506)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareReportQuerySelectAllRows(ExpressionQueryMechanism.java:1542)
at org.eclipse.persistence.queries.ReportQuery.prepareSelectAllRows(ReportQuery.java:1298)
at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:628)
at org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1047)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:577)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:824)
at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1690)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:271)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:187)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:139)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:123)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1376)
at examples.application.EmployeeService.findAllEmployeeProjectionObjects(EmployeeService.java:81)
at examples.application.EmployeeTest.main(EmployeeTest.java:55)
Java Result: 1
The exception states that your Employee Entity does not have an assigned Discriminator Value and is not part of a mapped Inheritance Hierarchy. As the spec requires TYPE to return the type discriminator if there is no Discriminator Value provided in the mappings then none can be returned by the TYPE operator. TYPE only works with mapped Inheritance.