I've only recently begun to develop with EJB systems, so please forgive
any naivete if I've made an oversight.
When calling methods against an entity bean with container managed
persistence running in JOnAS v2.3 (and v2.2.7) I get an oddball
ClassCastException for java.math.BigDecimal. I ran GenIC with
"-keepgenerated" so I could track it down. The problematic code is in the
generated implementation of ejbLoad(). This was an example of some of
the code causing this exception:
this.deptID = (java.lang.Integer)rs.getObject("dept_id");
if (rs.wasNull()) {
this.deptID = null;
}
In this case dept_id is an INTEGER in Oracle 8.0.5. (I'm using Oracle's
thin JDBC driver "classes111.zip".)
Clearly what's happening is that the JDBC driver is reading the numeric
value as a java.math.BigDecimal, which can't be cast to an Integer. From
the code I've seen, ejbLoad() will use ResultSet.getString() and
ResultSet.getDate(), but if the persistent field is of any other type then
it will use ResultSet.getObject(). Since ResultSet has its myriad of
accessors for the java.lang.* object types which will get the driver to do
its best to return the type you ask for, I replaced the code in ejbLoad()
to something like this:
int vInt = rs.getInt("dept_id");
if (rs.wasNull()) {
this.deptID = null;
} else {
this.deptID = new Integer(vInt);
}
and likewise again for a Double field. This fixed the problem.
(It's worth mentioning that creating entity beans with these datatypes
worked just fine for me. I didn't need to edit ejbStore().)
Is this a problem with JOnAS's CMP implementation? Is there rather a
better way to use it? Since the EJB specification doesn't tread into this
territory, I wonder if EJB containers are at all expected to deal with
persisting the java.lang.* object types?
Thanks.
----
This list is cross-posted to two mail lists. To unsubscribe,
follow the instructions below for the list you subscribed to.
For objectweb.org: send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe ejb-container-group".
For enhydra.org: send email to [EMAIL PROTECTED] and include
in the body of the message "unsubscribe ejb-container-group".