Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:59:39+00:00 2026-05-27T11:59:39+00:00

I have a descriptor class for a couple of domain classes. The descriptor class

  • 0

I have a descriptor class for a couple of domain classes. The descriptor class has a field ‘type’ which is an enum and indicates the type of the domain class. In some queries I want to return on or more descriptors and pass the type as constructor argument. 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 is thrown but the type is null in the results. Also it is not possible to pass the enum literal to the 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 persistence framework.

Is there a way to pass an enum literal into an SELECT NEW expression?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:59:39+00:00Added an answer on May 27, 2026 at 11:59 am

    No there is not, in general there is no way to reference to the fields in any class and it is also not possible to pass argument to the SELECT clause. Only valid arguments to the constructor expression are (from JPA 2.0 specification, page 174)

    • single_valued_path_expression
    • scalar_expression
    • aggregate_expression
    • identification_variable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Man class which also has 2 variable : description and name. At
I want to be able use python descriptors in a class which has the
I would like to create a file whose descriptor would have some customizable behavior.
I have this particular problem which follows me since couple days. I used the
I'd like to have the following setup: class Descriptor { public string Name {
I have a UIScrollView which I add a couple of subviews to (done in
We have servlet filter which verifies couple of session variables before JSF view display.
I have a descriptor class ReferredItem(): def __init__(self, method): self.method = method def __get__(self,
I have the following problem: there is a class with a couple of string
In C++ I have a constructor that accepts an object of class descriptor .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.