-->
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.  [ 5 posts ] 
Author Message
 Post subject: HBM Property Length
PostPosted: Mon Jul 28, 2008 10:53 am 
Newbie

Joined: Fri Nov 16, 2007 10:45 am
Posts: 7
Hi,

I am in the middle of adding length restrictions to my property mappings in my HBM files. It is all working fine and I am able to catch the exception in my code. I see that when the length restriction is violated, an NHibernate.ADOException is thrown with an inner exception of type System.Data.SqlClient.SqlException. This is all great. However, what I do not see and what I really need to see is which property was causing the exception. Is there any effecient way to determine this?

Thanks,
MetaDjinn


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 8:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
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.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 9:17 am 
Newbie

Joined: Fri Nov 16, 2007 10:45 am
Posts: 7
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!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 9:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
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?


Don't know for sure but don't think so, since it's based on the new event model introduced with 2.0. But 2.0 has reached RC1 now and it should be GA shortly.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 9:28 am 
Newbie

Joined: Fri Nov 16, 2007 10:45 am
Posts: 7
OK, I have added comments in my project to state that we should switch to NHibernate 2.0 and NHibernate.Validator when the are officially released. I can live with my temporary solution for our initial release.


Thanks,
Chris


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