wolli wrote:
The length attribute in the mapping file is only used for schema generation. It has no effect for crud operations. What you see is the ADO exception that is caused by the DB error when you exceed the column length. The exception contains the column name. You can try to retrieve the corresponding property name through the meta mode hibernate generates from the mapping files.
In my opinion a better approach would be validating the length before you actually save the objects. Have a look at the NHibernate.Validator project.
Hi wolli,
I did not see the actual property or column name in the exception. It just had the generated SQL and a message stating that "... data will be truncated." I looked at NHibernate.Validator, but it references NHibernate 2.0, which isn't released yet (correct?). Anyway, since the project that I am working on is an application that transfers data from a user file to the database (via NHibernate) by employing a "mapping" structure, the source records result in creating an instance of a persistent entity in a loop. I have just created some variables to track the current source column, the current entity property and the related destination column. I then catch the System.Data.OleDb.OleDbException and an ErrorCode of -2147467259 to indicate that a length restriction was validated. I then take the tracking variables to construct the appropriate message to log. This all works, but it is a bit cumbersome.
I would prefer to use NHibernate.Validator. If I were to take the source code for NHibernate.Validator, change the reference from NHibernate 2.0 to NHibernate 1.2.1.400 and rebuild it, would it still work?
Thanks!