Thanks a lot for your answer!
So does that mean that you have to duplicate every mapping file in
order for it to work??
It doesn't make much sense to me to have near identical xml mapping
files just to make
validation work. If you look at the example below, you see it's almost
the same mapping
just that the nhv file adds validation.
----------------------------------------------------------------
example.hbm.xml
----------------------------------------------------------------
<property name="FirstName" />
----------------------------------------------------------------
example.nhv.xml
----------------------------------------------------------------
<property name="FirstName">
<not-empty/>
<not-null/>
</property>
On 30 apr, 16:08, Fabio Maulo <[email protected]> wrote:
> NH is a product and *.hbm.xml is its format.
> NHV is another product and *.nhv.xml is its format.
>
> Two formats, two separate files.
>
> On Fri, Apr 30, 2010 at 9:47 AM, Anton <[email protected]> wrote:
> > Hi everyone,
>
> > I'm having a hard time configuring NHibernate Validator (NHV). For
> > some reason it doesn't see any of my mapped classes. NHibernate is
> > fully working, I changed all the mappings from *.nhv.xml to *.hbm.xml
> > and it works perfectly. However I want to use the NHV because of the
> > validation properties.
>
> > This is my config file:
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > <?xml version="1.0" encoding="utf-8" ?>
> > <configuration>
> > <!-- Configuration Sections In This File -->
> > <configSections>
>
> > <!-- NHibernate Section -->
> > <section
> > name="hibernate-configuration"
> > type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
> > />
>
> > <section
> > name="nhv-configuration"
> > type="NHibernate.Validator.Cfg.ConfigurationSectionHandler,
> > NHibernate.Validator" />
>
> > <!-- Log4Net Section -->
> > <section
> > name="log4net"
> > type="log4net.Config.Log4NetConfigurationSectionHandler,
> > log4net"
> > />
>
> > </configSections>
>
> > <nhv-configuration xmlns='urn:nhv-configuration-1.0'>
> > <property name='apply_to_ddl'>true</property>
> > <property name='autoregister_listeners'>true</property>
> > <property name='default_validator_mode'>UseExternal</property>
> > <property
>
> > name='message_interpolator_class'>NHibernate.Validator.Interpolator.DefaultMessageInterpolator,
> > NHibernate.Validator, Version=1.2.0.3001, Culture=neutral,
> > PublicKeyToken=70154e18752585bd</property>
> > <mapping assembly="MBMS.DAL" />
> > </nhv-configuration>
>
> > <!-- NHibernate Configuration -->
> > <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
> > <session-factory name="MBMS.DAL">
> > <property name="connection.provider">
> > NHibernate.Connection.DriverConnectionProvider
> > </property>
> > <property name="dialect">
> > NHibernate.Dialect.MsSql2005Dialect
> > </property>
> > <property name="connection.driver_class">
> > NHibernate.Driver.SqlClientDriver
> > </property>
> > <property name="connection.connection_string">
> > Data Source=(local)\SQLExpress;Initial Catalog=MBMS;Integrated
> > Security=True;Pooling=False
> > </property>
> > <property name="proxyfactory.factory_class">
> > NHibernate.ByteCode.Castle.ProxyFactoryFactory,
> > NHibernate.ByteCode.Castle
> > </property>
> > <mapping assembly="MBMS.DAL"/>
> > </session-factory>
> > </hibernate-configuration>
>
> > <!-- Log4Net Configuration -->
> > <log4net>
>
> > <!-- Define an output appender (where the logs can go) -->
> > <appender name="LogFileAppender"
> > type="log4net.Appender.FileAppender, log4net">
> > <param name="File" value="log.txt" />
> > <param name="AppendToFile" value="true" />
> > <layout type="log4net.Layout.PatternLayout, log4net">
> > <param name="ConversionPattern" value="%d [%t] %-5p %c [%x]
> > <%X{auth}> - %m%n" />
> > </layout>
> > </appender>
>
> > <!-- Note: Priority level can be ALL/DEBUG/INFO/WARN/ERROR/FATAL/
> > OFF -->
> > <!-- Setup the root category, set the default priority level and
> > add the appender(s) (where the logs will go) -->
> > <root>
> > <priority value="WARN" />
> > <appender-ref ref="LogFileAppender" />
> > </root>
> > </log4net>
>
> > <appSettings>
> > <add key="NUnitTestConfigValue" value="abc" />
> > </appSettings>
>
> > </configuration>
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> > And this is the code I use to configure NHV:
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > Configuration cfg = new Configuration();
> > cfg.Configure();
>
> > ValidatorEngine engine = new ValidatorEngine();
> > engine.Configure();
>
> > // Create session factory from configuration object
> > sessionFactory = cfg.BuildSessionFactory();
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> > Now when I check "cfg.ClassMappings.Count" it is always 0 when I use
> > the *.nhv.xml mapping files. The *.hmb.xml files work perfectly!
>
> > This is one mapping file:
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > <?xml version="1.0"?>
> > <nhv-mapping xmlns="urn:nhibernate-validator-1.0"
> > namespace="MBMS.DAL.Types" assembly="MBMS.DAL">
>
> > <class name="Person" table="Persons" lazy="false">
>
> > <!-- Identity mapping -->
> > <id name="ID">
> > <column name="ID" />
> > <generator class="identity" />
> > </id>
>
> > <!-- Simple mappings -->
> > <property name="FirstName">
> > <not-empty/>
> > <not-null/>
> > </property>
> > <property name="MiddleName">
> > <not-null/>
> > </property>
> > <property name="LastName">
> > <not-empty/>
> > <not-null/>
> > </property>
> > </class>
>
> > </nhv-mapping>
>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> > I have spend 4 hours already on just this issue and I'm running out of
> > idea's. What I don't understand is this that you have 2 configurations
> > right? The NHibernate configuration and the NHV configuration. If I
> > configure NHibernate it searches for *.hbm.xml files while the NHV
> > searches for *.nhv.xml files? So in that case
> > "cfg.ClassMappings.Count" would never ever be greater than zero right?
> > I don't get any errors when I compile and run my code but I also don't
> > retrieve any Persons in my database (while there are many in it).
> > Again I do retrieve every person when I change the *.nhv.xml files to
> > *.hbm.xml. Every XML file is set to "Embedded Resource".
>
> > I hope someone can help me out!
>
> > --
> > 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]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo
>
> --
> 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
> athttp://groups.google.com/group/nhusers?hl=en.
--
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.