cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Shea <>
Subject How to use #result with extended enumerations in SQLTemplate?
Date Thu, 18 Jun 2009 20:13:02 GMT
Hi guys,

I'm trying to use a SQLTemplate to retrieve some objects from my database.
The objects in question use an ExtendedEnumeration object to map from 
integers to an enum.


public enum TaskType implements ExtendedEnumeration
    TYPE_1( 1),
   public Object getDatabaseValue()
       return databaseValue; // This returns the integer passed in in 
the constructor.

My SQLTemplate string looks like this:

select distinct
#result('taskType' 'my.package.TaskType' '' 'taskType'),
#result('' 'int' '' 'id')

I've tried using both "my.package.TaskType" and "Integer" in the #result 
directive for retrieving the task type column.
Using the enum class as the java type, I get this exception:

java.lang.IllegalArgumentException: No enum const class 
    at java.lang.Enum.valueOf(

Using an Integer as the java type, I get a ClassCastException when I try 
to actually call Task.getTaskType() on the object I get back (it appears 
to be storing an Integer in the property on the object, so it blows up 
when it tries to return a TaskType enum).

Does SQLTemplate support extended enumerations in the #result directive? 
If so, how do I use this properly?



View raw message