Java 1.5 enums - ClassCastException

From: Ryan Holmes (rya..yperstep.com)
Date: Sun Jan 29 2006 - 19:27:39 EST

  • Next message: Andrus Adamchik: "Re: Java 1.5 enums - ClassCastException"

    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 - 19:27:47 EST