cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Shea <m...@nitido.com>
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.

eg:

public enum TaskType implements ExtendedEnumeration
{
    TYPE_1( 1),
    TYPE_2(2),
    ...
    ...
   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('T.id' '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 
my.package.TaskType.1
    at java.lang.Enum.valueOf(Enum.java:196)
    at 
org.apache.cayenne.access.types.ExtendedEnumType.lookup(ExtendedEnumType.java:167)
    at 
org.apache.cayenne.access.types.ExtendedEnumType.materializeObject(ExtendedEnumType.java:90)

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?

Thanks!


Shea.

Mime
View raw message