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:05:25 EDT