Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selecting elements from an enum.

 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this SO question might be helpful.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • 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.

 
Dave Tolls
Ranch Hand
Posts: 2100
15
  • Mark post as helpful
  • send pies
  • 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: 1869
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic