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!
|