views:

160

answers:

2

I just configured my NHibValidator. My NHibernate creates the DB schema. When I set MaxLenght="20" to some property of a class then in the database the length appears in the database column. I am doing this in the NHibValidator xml file. But the problem is that I have components and cannot figure out how to achieve this behaviour. The component is configured correctly in the Customer.hbm.xml file.

EDIT: Well, I found that Hibernate Validator users had the same problem two years ago. http://opensource.atlassian.com/projects/hibernate/browse/HV-25 Is this an issue for NHibernate Validator or it is fixed. If it is working tell me how please.

-----------------------------------------------------
public class Customer
{
public virtual string Name{get;set;}
public virtual Contact Contacts{ get; }
}
-----------------------------------------------------
public class Contact
{
public virtual string Address{get;set;}
}
-----------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<nhv-mapping xmlns="urn:nhibernate-validator-1.0"
                        namespace="MyNamespace"
                        assembly="MyAssembly">
<class name="Customer">

   <property name="Name">
     <length max="20"/>
   </property>

   <property name="Contacts">
         <notNull/>
         <valid/>
   </property>

</class>
</nhv-mapping>
-----------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<nhv-mapping xmlns="urn:nhibernate-validator-1.0"
                        namespace="MyNamespace"
                        assembly="MyAssembly">
<class name="Contact">

   <property name="Address">
         <length max="50"/>
         <valid/>
   </property>

</class>
</nhv-mapping>
-----------------------------------------------------
A: 

Well, this should be a bug. I posted this to NHibernate issue tracker.

http://216.121.112.228/browse/NHV-82

mynkow
A: 

I have the same issue using the latest build of NHibernate and NHibernate Validator, however I'm using the fluent configuration.

Jaimal Chohan