Ryan,
What I discovered when testing your case is that Cayenne can't handle
an Enum which is an inner class. It has to be in its own top-level
class. Once I moved it to the top, everything started to work.
While I was getting a different error (ClassNotFoundException), I
think the reason may be the same. I'll open a bug report regarding
Enums as inner classes and see what we can do. In the meantime, could
you please try the fix I described above.
Andrus
On Jan 29, 2006, at 7:27 PM, Ryan Holmes wrote:
> I'm trying to use JDK 1.5 enums in Cayenne 1.2M10 (Windows modeler)
> with no luck so far. A ClassCastException is thrown when invoking
> the superclass getter for the enum property.
>
> My enum type (com.hyperstep.bulldog.domain.User.UserStatus) is
> specified as the "Java Type" in the ObjEntity attribute. The
> corresponding db attribute is a VARCHAR. The relevant parts of the
> generated superclass look like this:
>
> public class _User extends org.objectstyle.cayenne.CayenneDataObject {
> ...
> public static final String STATUS_PROPERTY = "status";
> ...
> public void setStatus
> (com.hyperstep.bulldog.domain.User.UserStatus status) {
> writeProperty("status", status);
> }
> public com.hyperstep.bulldog.domain.User.UserStatus getStatus() {
> return (com.hyperstep.bulldog.domain.User.UserStatus)
> readProperty("status");
> }
> ...
> }
>
> UserStatus is a simple enum inside my User domain class:
>
> public class User extends _User {
> ...
> public static enum UserStatus {
> REGISTERED, AUTHORIZED, LOCKED_OUT, BANNED, DELETED
> }
> ...
> }
>
> setStatus() works fine and the correct UserStatus name is saved to
> the db. The ClassCastException occurs after fetching the object and
> calling getStatus():
>
> java.lang.ClassCastException: java.lang.String
> at com.hyperstep.bulldog.domain.auto._User.getStatus(_User.java:
> 150)
>
> I'm probably missing something really simple here, but I'm new to
> Cayenne and not sure what to try next.
> FYI, I noticed that the modeler is using version 1.1 templates and
> I don't know how to specify 1.2 templates or if that's even related
> to the enum problem.
This archive was generated by hypermail 2.0.0 : Sun Jan 29 2006 - 20:05:16 EST