-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Double trouble: Invalid numeric parameter
PostPosted: Sat Mar 12, 2005 6:53 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Hibernate version 2.1
Underlying database: SapDB

I have been stuck for some time with the exception shown below which is thrown whenever I try to persist bean entities which contain properties of type double. During the debugging process I am mapping my java doubles to the sql type Float(38) which is the most precise sapdb floating point numbers, containing up to 38 digits (not bits) which should be more than enough to represent Java doubles which contain a 52 bit number (the mantissa) and an 11 bit exponent. It does not matter what my double values are - the exception is thrown EVEN if I try to persist 0.0.

If anyone could come up with an idea what could be wrong, I would be grateful.

Randahl


Excerpt from mapping document (width and height are Double properties):
<property name="width">
<column name="width" sql-type="Float(38)"/>
</property>
<property name="height">
<column name="height" sql-type="Float(38)"/>
</property>

Exception:

Caused by: com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3018] (at 85): In
valid numeric parameter
at com.sap.dbtech.jdbc.packet.ReplyPacket.createException(ReplyPacket.ja
va:69)
at com.sap.dbtech.jdbc.ConnectionSapDB.throwSQLError(ConnectionSapDB.jav
a:748)
at com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:422)

at com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:316)

at com.sap.dbtech.jdbc.CallableStatementSapDB.execute(CallableStatementS
apDB.java:382)
at com.sap.dbtech.jdbc.CallableStatementSapDB.execute(CallableStatementS
apDB.java:291)
at com.sap.dbtech.jdbc.CallableStatementSapDB.executeUpdate(CallableStat
ementSapDB.java:697)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdat
e(WrappedPreparedStatement.java:335)
at net.sf.hibernate.persister.NormalizedEntityPersister.update(Normalize
dEntityPersister.java:695)
... 42 more


Top
 Profile  
 
 Post subject: Floats too
PostPosted: Sat Mar 12, 2005 7:52 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
For testing purposes I just converted all doubles to floats - same story.

R.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 9:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Figure out how to solve your problem in direct JDBC - and then you will know how to solve it in Hibernate,


Top
 Profile  
 
 Post subject: JDBC
PostPosted: Sat Mar 12, 2005 1:59 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Thanks for the tip. I just created a simple JDBC program which connects directly to the database and tries to insert all kinds of double values into my table, but I am unable to reproduce the error. I wonder what could be special about hibernates way of communicating with my database which makes my database throw the exception?

I cannot yet figure out why updating a bean containing a Double or a Float property would be any different than what my test program does... this really puzzles me...

The program below inserts 10000 doubles of all kinds into my database and it runs without failure. However inserting just a few entities containing double values through hibernate results in the "Invalid Numeric Parameter" exception mentioned.

Any suggestions would be highly appreciated.

Randahl



The program:
for(int i = 0; i < 10000; i++) {
double f = random.nextDouble();
if(random.nextBoolean())
f *= -1;
int exp = random.nextInt(30);
f *= Math.pow(10, exp);
statement.executeUpdate(
"insert into double_test " +
"values (" + i + ", " + f + ")"
);
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 5:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
User PreparedStatements, Hibernate does too all the time.


Top
 Profile  
 
 Post subject: Use of prepared statements
PostPosted: Sat Mar 12, 2005 7:44 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Thanks Michael. - I tried this, but to no avail. As you can see from the program below, I carry out 100.000 inserts without reproducing the error. Has anyone got any other ideas about why Hibernate fails to insert doubles even though doubles can be inserted without problems through jdbc?

My entity is a bean containing a mix of Integer, Float and Double properties, and I use the default mappings.

This is really a hard one to crack. Thanks for your time...
Randahl


PreparedStatement preparedStatement = connection.prepareStatement(
"insert into double_test " +
"values (?, ?)"
);
for(int i = 0; i < 100000; i++) {
double f = random.nextDouble();
if(random.nextBoolean())
f *= -1;
int exp = random.nextInt(30);
f *= Math.pow(10, exp);
preparedStatement.setInt(1, i);
preparedStatement.setDouble(2, f);
preparedStatement.execute();
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 7:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, there is nothing much I can do but something you can do ... debug the stuff. The Hibernate Source is available, grab a debugger and step into the Type classes, see what operations Hibernate is performing to the PreparedStatement ... I suspect some wrong type.

Did you try explicitly setting type="" on the properties?


Top
 Profile  
 
 Post subject: Mapping document
PostPosted: Sat Mar 12, 2005 7:53 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Here is the central parts of my mapping document - for clarity I have replaced irrelevant information with "[...]"

As far as I can tell this is standard stuff really - have I overlooked something?

Randahl


<joined-subclass [...]
<key column="DC_ID"/>
<property name="backgroundColor" type="[...]SrgbColorType">
<column name="BACKGROUND_COLOR_RED" />
<column name="BACKGROUND_COLOR_GREEN" />
<column name="BACKGROUND_COLOR_BLUE" />
<column name="BACKGROUND_COLOR_ALPHA" />
</property>
<property name="x">
<column name="x" />
</property>
<property name="XUnit" type="[...]UnitType">
<column name="X_UNIT" sql-type="VARCHAR(30)"/>
</property>
<property name="y">
<column name="y" />
</property>
<property name="YUnit" type="[...]UnitType">
<column name="Y_UNIT" sql-type="VARCHAR(30)"/>
</property>
<property name="width">
<column name="width"/>
</property>
<property name="widthUnit" type="[...]UnitType">
<column name="WIDTH_UNIT" sql-type="VARCHAR(30)"/>
</property>
<property name="height">
<column name="height" />
</property>
<property name="heightUnit" type="[..]UnitType">
<column name="HEIGHT_UNIT" sql-type="VARCHAR(30)"/>
</property>
<property name="ZIndex">
<column name="Z_INDEX"/>
</property>
</joined-subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 7:56 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
:-) we just posted at the same time... I'll try out setting the types explicitly - great Idea. Did you notice anything perculiar about the mapping document?

Randahl


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 8:20 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
I tried explicitly setting the type="float" on each property, but that was not it. Using my client program I arbitrarily selected some float values, and after a few attempts I got the error again. This bug is starting to impress me :-)

R.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 8:40 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
Major break through!!!

I have found a consistent reproducable bug situation. The error comes each time I enter the value 0f or 0.0. This is not caused by hibernate, because I can reproduce this error with JDBC using the following three statements:

preparedStatement.setInt(1, 2);
preparedStatement.setDouble(2, 0.0);
preparedStatement.execute();

I know sapdb can store the floating point number 0 (just to be absolutely sure, I inserted a 0 value using the sapdb SQL Studio client).

This might mean big trouble - the stack trace refers to the line
com.sap.dbtech.jdbc.ConnectionSapDB.execute(ConnectionSapDB.java:422)
which could indicate a bug in the sabdb driver...

R.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 9:03 pm 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
That was it! - Problem solved.

I updated my driver to version 7_6_00_00_3360 and now it works!

I know this was not a Hibernate related bug after all so thank you very much for inspiring me to try out new things - this finally lead to a solution.

Randahl


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.