• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Selecting elements from an enum.

 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to use criteria queria to get a selection of Enum data.

For example

Select a.Name a.value a.enum1 from Customer a

But a.enum1 is an object and not a string and that I think is a problem.

How do I retreive the enum as a string. The result is a Tuple.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
List<Selection<Object>> columnSelections = new ArrayList<Selection<Object>>();
columnSelections.add(root.get("enum1"))

The colum selection above is the problem. Its an enum object. How do I get the string out
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this SO question might be helpful.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I looked at that before but that issue can be represented in SQL like this

Select Car from Car a where a.enum1 is ('blue','red');

I want the following as result

Select a.enum1 from Car a

Now since the enum1 is an enum within the Car object that is my issue as to how to represent it in String in the result.

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not clear on what you mean by "represent it in String in the result".

What exactly is the issue you are encountering?

Can you show us relevant code?
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
columnSelections.add(root.get("enum1"));

for example when I use a columnSelection to select a enum Object within Customer then there are no results.

 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on this article, you should always use the fully qualified name when using an enum in a condition. But that's probably not what you are looking for either, because it seems you want to add the enum value (or maybe even its string representation) in the select list. And using the Criteria API you seem to have an issue with the enum part. Correct?

Can you share the appropriate code and (if available) the appropriate error message you get as well?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic