Actually, I don't think changing the type mappings in the JAWS configuration
solves the problem.  I've been recently trying to port an internal benchmark
app from IAS & WebLogic to jBoss.  I am definately NOT an Oracle expert, so
you may want to take the following with a grain of salt.  The basic problem
with Oracle is that it doesn't really have a true "Integer" type - all
Integers are basically represented as DECIMAL(x,0) types.  If you specify an
INTEGER in your database construction , you get a DECIMAL(38,0), which holds
considerably larger numbers than the range of a normal 32-bit integer!

The other problem is that, as Heiko noted, the Oracle driver seems to return
a java.math.BigDecimal type when you do a rs.getObject() call, NOT a
java.lang.Integer.  This happens even when the underlying type is small
enough to fit as an Integer (e.g. DECIMAL(8,0)).

This problem should be addressed eventually, since Oracle is a major db.
Here's how the other two EJB vendors I've been looking at address this
problem:

Weblogic decides how to convert the return type of the result from the
rs.getObject() call depending on the size of the underlying DECIMAL type.
For instance, if the field is a DECIMAL(9,0) or smaller, it converts it to
an Integer, if it's a DECIMAL(10,0) -> DECIMAL(x,0) it converts it to a
Long, if it's a DECIMAL(x + 1, 0) or greater, it returns it as a BigDecimal,
etc.  This is a huge pain in the ass, because it means your CMP mappings are
basically decided by arbitrary size restrictions in your database.  That
means that if you create your table specifying your fields as INTEGER (i.e.
DECIMAL(38,0)), BEA's CMP implementation breaks and you spend hours or days
scouring newsgroups to figure out exactly why.  And THEN, you have to change
your database schema to match they're undocumented silliness.  Grrrrrrr....

On the other hand, IAS just converts the value according to what the CMP
type is.  This runs the risk of overflow if the programmer is careless, but
is eminently more reasonable, IMHO.

So where does this lead us?  The problem Heiko found in the code is this:

In org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.loadEntity (around line
697), we have this:

            {
               // Load primitive

               // TODO: this probably needs to be fixed for BLOB's etc.
               ((Field)cmpFields.get(i)).set(ctx.getInstance(),
rs.getObject(idx++));
            }


Note that this code fails for Oracle, since rs.getObject(idx++) is returning
a BigDecimal (EVEN IF THE SQL USED TO CREATE THE TABLE SPECIFIED AN
INTEGER), and BigDecimals can't be cast to Integers!  What (I guess) should
be done is that the appropriate getX() call should be called depending on
the CMP type specified in JAWS.  For instance, if the CMP field is an int or
an Integer, then you need to call rs.getInt() and not rs.getObject().  If
it's a Long, then you need to call rs.getLong().  Similar code probably has
to be done for the store method as well.

Ugly.  But as long as there are 10-ton gorillas in the world, I guess
everyone has to stock a lot of bananas....


Jeff 8-)

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Rickard �berg
Sent: Thursday, May 25, 2000 10:10 AM
To: jBoss
Subject: Re: [jBoss-User] JAWS/Oracle: BigDecimal and INTEGER?


Hey

Heiko Seebach wrote:
> Hi, I'm trying to use JBoss (newest CVS) with Oracle and I made a class
> "mypackage.category.beans.CategoryEntityBean".
<snip>

If you check the "Type mappings" in the JAWS configuration you will find
the Oracle mappings. Simply change the int mapping.

/Rickard

<snip>



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to