numeric(7,2) with EJB3 BigDecimal ?

  • Hi all:

    I'm writing a J2EE application with EJB3, and SqlServer 9. I'm using the Merlia JDBC driver,

    version 7.07.

    I have a table with two numeric fields, one numeric(7,2) and one numeric(3,2).

    I have specified them in the entity bean as BigDecimals, and with @Column( columnDefinition="numeric(7,2)", ... )

    and the other with (3,2).

    When I run my unit tests, I set the entity's fields using a new BigDecimal (according to java/sqlserver mapping

    rules at http://msdn.microsoft.com/en-us/library/ms378878.aspx) with a value of 0.0 - and it comes back with:

    10:44:30,212 WARN org.hibernate.util.JDBCExceptionReporter SQL Error: 8115, SQLState: 22003

    10:44:30,212 ERROR org.hibernate.util.JDBCExceptionReporter [host]Arithmetic overflow error converting numeric to data type numeric.

    Msg 8115, Level 16, State 8, Line 1, Sqlstate 22003

    10:44:30,212 ERROR org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session

    org.hibernate.exception.DataException: could not insert: [edu.msu.ais.d6300.ejb.entity.Department]

    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)

    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

    ...more....

    when I try to create ( "em.persist( obj )" ) the record.

    I can create other record types in other tables; SqlServer does not seem to be the issue.

    Thanks for any insight....

  • I think I may have found my own answer.

    I was creating the value in the two numeric fields by using:

    protected double NUMERIC_VALUE = 0.00d;

    then,

    obj.setNumericfield( new BigDecimal( NUMERIC_VALUE ) );

    When I changed the setter statement to:

    obj.setNumericfield( new BigDecimal("0.00"));

    it started working.

    I didn't think that creating a BigDecimal with a double would cause a numeric overflow,

    but it appears that was the issue.

    BTW, we're using JDK 1.6, with JBoss 5.1.0.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply