users@glassfish.java.net

Scary TopLink error when using boolean instead of Boolean

From: <glassfish_at_javadesktop.org>
Date: Sat, 23 Feb 2008 20:46:01 PST

I added a boolean field to an entity and (since this is a production app) manually added a matching boolean column to the database.

When the first entity was retrieved, I got this error message:

Exception [TOPLINK-32] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: Trying to set value [0] for instance variable [open] of type [boolean] in the object. The specified object is not an instance of the class or interface declaring the underlying field, or an unwrapping conversion has failed.
Internal Exception: java.lang.IllegalArgumentException: Can not set boolean field com.horstmann.activelecture.entity.Topic.open to java.lang.Integer
Mapping: oracle.toplink.essentials.mappings.DirectToFieldMapping[open-->ITEMBASE.OPEN]
Descriptor: RelationalDescriptor(com.horstmann.activelecture.entity.Topic --> [DatabaseTable(ITEMBASE)])

The legacy entity had a field of NULL in the OPEN column, and apparently NULL was converted to 0 and that couldn't be converted to false.

I fixed this by changing my entity field from boolean to Boolean and by dealing with the possibility of a NULL in the isOpen method. Clearly, that is the right way of doing it. But it took me quite some time to get there because the error message was so confusing.

I am not sure it's worth reporting as a bug, but I put it here in case someone else runs into it.
[Message sent by forum member 'cayhorstmann' (cayhorstmann)]

http://forums.java.net/jive/thread.jspa?messageID=260601