Decimal (Precision,Scale) values are forced to take default values of

248 views
Skip to first unread message

Vani

unread,
Jan 23, 2008, 3:03:51 AM1/23/08
to NHibernate-Hispano, sriva...@gmail.com
When inserting data into a SQL Server database from my application
that is utilizing NHibernate ver. 1.0, the format for my decimal
datatype values is being forced to decimal(19,5), regardless of the
precision defined for the attribute in the SQL Server table. This
results in decmial values being truncated before being written to the
SQL Server database. An example of the stored procedure call that is
generated by the NHibernate environment when my application calls the
Session.Save() method is as follows:

exec sp_executesql N'INSERT INTO TEST_TABLE(DECIMAL_VALUE1,
DECIMAL_VALUE2, LONG_VALUE1) VALUES (@p0, @p1, @p2); select
SCOPE_IDENTITY()', N'@p0 decimal(19,5),@p1 decimal(19,5),@p2 bigint',
@p0 = 9.94434, @p1 = 9.94434, @p2 = 5583

It is not obvious to me what is causing the "decimal(19,5)"
specification to be included for my decimal datatype values in the
stored procedure query generated from NHibernate. Within the SQL
Server table, the attributes that represent DECIMAL_VALUE1 and
DECIMAL_VALUE2 originally were defined to be decimal(16,6), but are
now defined as decimal(18,12). However, the stored procedure still
specifies these values as datatype decimal(19,5) as shown above.

I checked my nhibernate.config and mapping files and didn't see a
specification for this parameter or a decimal datatype precision
value, so I'm not sure if/where this is being defined.

Any help to clarify this behavior or to look into this possible bug
would be appreciated.

Thank you,
Vani

Dario Quintana

unread,
Jan 23, 2008, 6:16:42 AM1/23/08
to NHibernate-Hispano
Hi,

The Jira is down, I'll take a look later on this issue.

BTW, I think that you can create a UserType with your needs for the
moment.

Dario Quintana

unread,
Jan 23, 2008, 10:24:05 AM1/23/08
to NHibernat...@googlegroups.com
NHibernate not make restriction about decimal, if you use SQL Server, try to configurate a column with decimal(19,15), and later Save an object, NHibernate will persist without truncate.

When you generate using NHibernate.Tool.hbm2ddl yes, it generate a decimal(19,5), but you have not restrictions to change it in the db.



Fabio Maulo

unread,
Jan 28, 2008, 7:52:34 AM1/28/08
to NHibernat...@googlegroups.com
In NH2.0 I made some changes to NH-Types to accept Percision-Scale modificators.
Right now I don't remember if the DecimalType accept the new feature.
I'll check it in some days.

Bye.
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages