-->
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.  [ 4 posts ] 
Author Message
 Post subject: MS SQL Server and BigDecimal mapping problem
PostPosted: Thu Sep 23, 2004 3:02 pm 
Newbie

Joined: Thu Sep 23, 2004 1:57 pm
Posts: 6
Using Hibernate 2.1.6 and SQLServer dialect for SQL Server 2000 (JSQL driver) during schema export I got error. Looks like hibernate converts BigDecimal to numeric(19,255) and it's wrong for SQL server.
The question is - is it BUG? and how to change default mapping (I know i can change it in mapping files but we generate them and we have hundreds of them)

-----------------------

ERROR during schema export:

Code:
[schemaexport] 20:52:47,890 ERROR SchemaExport:154 - Unsuccessful: create table Product (id numeric(19,0) not null, version numeric(19,0) not null, name varchar(255) null, price numeric(19,255) null, image image null, primary key (id))

[schemaexport] 20:52:47,890 ERROR SchemaExport:155 - The scale (255) for column 'price' must be within the range 0 to 19.


-----------------------

The MAPPING for Product is:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="pl.infovide.example.component.order.data.model.Product"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="increment">
            </generator>
        </id>

        <version
            name="version"
            type="java.lang.Long"
            column="version"
            access="property"
            unsaved-value="null"
        />

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
        />

        <property
            name="price"
            type="java.math.BigDecimal"
            update="true"
            insert="true"
            access="property"
            column="price"
        />

        <property
            name="image"
            type="java.sql.Blob"
            update="true"
            insert="true"
            access="property"
            column="image"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Product.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 08, 2004 1:40 pm 
Newbie

Joined: Sat Sep 25, 2004 9:37 am
Posts: 1
I had exactly the same issue.

I overcame it by setting the length attribute on each property using the BigDecimal type to19 or lower.

This appears to be a restriction of SQLServer in that it can only have a precision of 19 or less.

Hope that helps.


Top
 Profile  
 
 Post subject: This may actually be a hibernate bug
PostPosted: Thu Feb 17, 2005 7:10 pm 
Newbie

Joined: Thu Feb 17, 2005 7:05 pm
Posts: 1
I think this may be a bug with the hibernate code. If you look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_3grn.asp


The syntax states that precision comes before scale in the create table syntax for numeric types.

This leads me to believe that the syntax:

create table Product (id numeric(19,0) not null, version numeric(19,0) not null, name varchar(255) null, price numeric(19,255) null, image image null, primary key (id))


is wrong, the numeric colums should be switched around :

create table Product (id numeric(0,19) not null, version numeric(0,19) not null, name varchar(255) null, price numeric(255,19) null, image image null, primary key (id))

The first number is the precision. As microsoft says:

"Specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point."



The second number is the scale:

"The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision."


Anyone know how to fix this?


Top
 Profile  
 
 Post subject: Answer
PostPosted: Mon Feb 21, 2005 9:34 am 
Newbie

Joined: Mon Feb 21, 2005 9:30 am
Posts: 1
I decided this problem :

public BigDecimal getPrice() {
if (price != null) {
price = price.setScale(2, BigDecimal.ROUND_FLOOR);
}
return price;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.