Dear Everybody,
I've played with Nhibernate 3 Alpha 2 for a while and recently found a
bit confusing behaviour at least from standpoint of compatability with
version 2.1.2.
A problem occurs when I try to insert(didn't try to update but I
suppose it can have the same problem) string value to column with
limited length.
In 2.1.2 when such insert occurs my db engine(MSSQL SERVER 2008)
throws an exception "String or binary data would be truncated." which
gives me ability to rollback transaction at least if business layer
didn't check length of a field. With the version 3.0 Alpha 2 db engine
doesn't throw any exception on such insert because value is truncated
automagically by nhibernate. Generated SQL:
2.1.2:
exec sp_executesql N'INSERT INTO Customers (FirstName) VALUES (@p0);
select SCOPE_IDENTITY()',N'@p0 nvarchar(16)',@p0=N'MoreThan3Symbols'
3.0:
exec sp_executesql N'INSERT INTO Customers (FirstName) VALUES (@p0);
select SCOPE_IDENTITY()',N'@p0 nvarchar(3)',@p0=N'Mor'
My mapping:
<class name="TruncateBug.Customer,TruncateBug" table="Customers">
<id name="CustomerId" column="CustomerId">
<generator class="native"/>
</id>
<property name="FirstName" column="FirstName" length="3"/>
</class>
And the code that doesn't produce exception anymore:
var invalidCustomer = new Customer() { FirstName =
"MoreThan3Symbols" };
int id = (int)session.Save(invalidCustomer);
And yes session will contain Customer object with full length
FirstName which could lead to a lot of misunderstanding in further
usage of the Customer object in scope of this session.
Maybe it's not a bug but a feature but then I hope there is a way to
configure nhiberate to throw exception as previously and to not try to
create magic for me.
Thanks in advance,
Yours sincerely,
Maxim Filimonov
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.