Re: Enums

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Aug 09 2007 - 11:25:42 EDT

  • Next message: Andrus Adamchik: "Re: Enums"

    Well, it won't use a user defined attribute ("newName" in your case).
    It will use either ENUM name - "FEMALE" or "MALE", or enum index.

    > Notice for the gender column it didn't use "F" or "M" as the value.
    > It used test.GenderEnumeratio..551336 and
    > test.GenderEnumeratio..974996.

    This is likely a logging artifact.

    Andrus

    On Aug 9, 2007, at 6:04 PM, Michael Gentry wrote:

    > Well, maybe I'm doing something wrong, but I just wrote a test case
    > and it crashes. My main program is:
    >
    > DataContext dataContext = DataContext.createDataContext();
    >
    > Person aGal = (Person) dataContext.newObject(Person.class);
    > Person aGuy = (Person) dataContext.newObject(Person.class);
    >
    > aGal.setFirstName("Lisa");
    > aGal.setLastName("Simpson");
    > aGal.setGender(GenderEnumeration.FEMALE);
    >
    > aGuy.setFirstName("Bart");
    > aGuy.setLastName("Simpson");
    > aGuy.setGender(GenderEnumeration.MALE);
    >
    > dataContext.commitChanges();
    >
    >
    > And it crashed with:
    >
    > Aug 9, 2007 10:59:35 AM org.apache.cayenne.access.QueryLogger logQuery
    > INFO: INSERT INTO Person (firstName, gender, lastName, primaryKey)
    > VALUES (?, ?, ?, ?)
    > Aug 9, 2007 10:59:35 AM org.apache.cayenne.access.QueryLogger
    > logQueryParameters
    > INFO: [batch bind: 'Lisa', test.GenderEnumeratio..551336,
    > 'Simpson', 220]
    > Aug 9, 2007 10:59:35 AM org.apache.cayenne.access.QueryLogger
    > logQueryParameters
    > INFO: [batch bind: 'Bart', test.GenderEnumeratio..974996,
    > 'Simpson', 221]
    > Aug 9, 2007 10:59:35 AM org.apache.cayenne.access.QueryLogger
    > logQueryError
    > INFO: *** error.
    > org.postgresql.util.PSQLException: ERROR: value too long for type
    > character(1)
    >
    > Here is my enum:
    >
    > public enum GenderEnumeration
    > {
    > FEMALE("F"), MALE("M");
    >
    > private String newName;
    >
    > GenderEnumeration(String s)
    > {
    > newName = s;
    > }
    > public String toString()
    > {
    > return newName;
    > }
    > }
    >
    > Notice for the gender column it didn't use "F" or "M" as the value.
    > It used test.GenderEnumeratio..551336 and
    > test.GenderEnumeratio..974996.
    >
    > Thanks,
    >
    > /dev/mrg
    >
    > PS. I also tried it without the toString() method in the enum.
    >
    >
    > On 8/9/07, Andrus Adamchik <andru..bjectstyle.org> wrote:
    >>
    >> On Aug 9, 2007, at 4:33 PM, Michael Gentry wrote:
    >>
    >>> Cayenne handles Java 5 enums automatically? You don't have to have,
    >>> in your custom type (the enum), setJdbcObject or
    >>> materializeObject and
    >>> don't have to register the enum with Cayenne?
    >>
    >>
    >> Yep it does.
    >>
    >> Andrus
    >>
    >>
    >



    This archive was generated by hypermail 2.0.0 : Thu Aug 09 2007 - 11:26:04 EDT