-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to query for enum-types? (working, but ugly?)
PostPosted: Wed Jan 17, 2007 9:26 pm 
Newbie

Joined: Thu Jul 14, 2005 5:19 am
Posts: 7
Location: Munich, Germany
Hibernate 3.2, Java 5 (or even 6)
----
I'm just in the process of converting some of our ugly "public static final int"-constants into nice and clean "enums" (Java 5).

It was nice to see this work (almost) immediately with Hibernate (annotations). :-)

However, I have a "real problem" with our queries.
The "old version" for a very very simple one looks like this:
select count(*) from CONTENT c where c.state=1

In order to avoid bothering all of you with stupid questions, I did a lot of reading and searching and the "correct" (and only?) way of doing this now is using "fully qualified" names for the enums. The above then becomes:
select count(*) from CONTENT c where c.state=com.somecompany.package.content.Content$State.VALIDATED

This works! Everything else (I tried) failed.

However, a still rather simple query
select count(*) from CONTENT x where state=2 and (type=4 or type=5 or type=7)

would then turn into
select count(*) from CONTENT x where state=com.somecompany.package.content.Content$State.VALIDATED and (type=com.somecompany.package.content.Content$Type.INTERNAL or type=com.somecompany.package.content.Content$Type.EXTERNAL or type=com.somecompany.package.content.Content$Type.REF)

Uhhh... this is not nice :-(((
Some of the more complex queries would become completely unreadable...

Is there any better way? Why is this so complicated? When the query is "resolved", Hibernate sees that I'm checking for a certain value in the "type"-field and the type-field's class is com.somecompany.package.content.Content.Type. Can this not be resolved more easily?

Any hope for Hibernate 3.3?
If this change makes our queries unreadable, I probably won't do it. Everybody would hate me for it :-((

I really did try to find other solutions, but almost everything else I found seems to be "obsolete" (well... more or less) and deals with UserTypes and other ways of saving enums... I don't really want to introduce lots of extra classes if the above is "almost entirely working"...

Any hints or comments appreciated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.