I have a descriptor class for a pair of domain classes. The descriptor class has a type field, which is an enumeration and indicates the type of the domain class. In some queries, I want to return to or more descriptors and pass the type as an argument to the constructor. So my idea was to pass it as a query parameter:
String jpql = "SELECT NEW model.ModelDescriptor" + "(t.id, t.name, t.description, :modelType) ... "; TypedQuery<ModelDescriptor> query = em.createQuery(jpql, ModelDescriptor.class); query.setParameter("modelType", ModelType.forClass(clazz)); List<ModelDescriptor> list = query.getResultList();
This does not work. No exception was thrown, but type null in the results. It is also not possible to pass an enumeration literal to a query:
"SELECT NEW model.ModelDescriptor (f.id, f.name, f.description, model.ModelType.FLOW) ... "
edit I get the following stack trace:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Error compiling the query [SELECT model.ModelDescriptor(f.id, f.name, f.description, model.ModelType.FLOW) FROM Flow f WHERE flow.id = :flowId], line 1, column 78: unknown identification variable [model]. The FROM clause of the query does not declare an identification variable [model]. at org.eclipse.persistence.internal.jpa.EntityManagerImpl. createQuery(EntityManagerImpl.java:1477) at org.eclipse.persistence.internal.jpa.EntityManagerImpl. createQuery(EntityManagerImpl.java:1497)
I use EclipseLink as the basis of conservation.
Is there a way to pass an enumeration literal to a SELECT NEW expression?
source share