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 [EMAIL PROTECTED] and
[EMAIL PROTECTED]
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', [EMAIL PROTECTED],
'Simpson', 220]
Aug 9, 2007 10:59:35 AM org.apache.cayenne.access.QueryLogger
logQueryParameters
INFO: [batch bind: 'Bart', [EMAIL PROTECTED],
'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 [EMAIL PROTECTED] and
[EMAIL PROTECTED]
Thanks,
/dev/mrg
PS. I also tried it without the toString() method in the enum.
On 8/9/07, Andrus Adamchik <[EMAIL PROTECTED]> 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