Luke Brown wrote:
> 
> 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.
> 

Hi,

You have perfectly understand what the problem is.
Indeed, it's a problem with JOnAS's CMP implementation on Oracle in this
case.
Note that this same one example works fine on InstantDB, PostgreSQL or
InterBase.
The problem is that JDBC and SQL statements is not really portable,
essentially because of mapping types problem.
It's so not really possible to have same JDBC code on various database.
In a future version of JOnAS, persistency support will be based on JORM,
which is another ObjectWeb project providing generic support for object
persistency, to solve this kind of problem and to support the EJB 2.0
persistency.

Kind regards.
H�l�ne.
-- 
-=- H�l�ne JOANIN -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  mailto:[EMAIL PROTECTED]   http://www.evidian.com
  Phone: 33.4.76.29.73.53            Fax: 33.4.76.29.76.00
  Download our EJB Server JOnAS at http://www.objectweb.org
----
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".

Reply via email to