Hi
I've found a bug - not related to NHibernate. Definition of getters and
setters in a Car class was generating stackoverflow. Should be:
[NotNull] private string manufacturer { get; set; }
It didn't solve issue with unnecessary dependence to MySQL and Hibernate,
but at least code is executing correctly.
Still looking for solution to remove this dependency.
Best
Mikolaj
W dniu wtorek, 22 listopada 2016 11:47:28 UTC+1 użytkownik Mikołaj Habdank
napisał:
>
> Hi
>
> Please could you share a working example of a code for NHibernate
> Validator 1.3.2.4000 without using NHibernate ORM (currently in my code
> 4.0.4.4000 as a dependency)?
> I've been able to create a working solution in java and and now I'm stuck
> with configuration for validator in C#. For my PoC I'm using mono 4.6.
> We need data validation across our pipeline (mixed C3 and scala
> environment - spark) and hibernate validator looks solid. We do not want to
> use Hibernate ORM.
>
> I'm trying to use code mappings like this:
> namespace nhcar
> {
> public class Car
> {
> [NotNull]
> private string manufacturer
> {
> get { return manufacturer; }
> set { manufacturer = value; }
> }
>
> [NotNull]
> [Length(Min = 2, Max = 14)]
> private string licensePlate
> {
> get { return licensePlate; }
> set { licensePlate = value; }
> }
>
> [Min(2)]
> private int seatCount
> {
> get { return seatCount; }
> set { seatCount = value; }
> }
>
> public Car(string manufacturer, string licensePlate, int
> seatCount)
> {
> this.manufacturer = manufacturer;
> this.licensePlate = licensePlate;
> this.seatCount = seatCount;
> }
>
> public Car()
> {
> }
> }
> }
>
>
> And this is my main:
> public static void Main(string[] args)
> {
> var cfg = new NHibernate.Cfg.Configuration();
> cfg.Configure();
> Fluently.Configure()
> .Mappings(m =>
> m.FluentMappings
> .AddFromAssemblyOf<Car>())
> .BuildConfiguration();
>
> var validatorEngine = new ValidatorEngine();
> cfg.Initialize(validatorEngine);
> validatorEngine.Configure();
>
> Console.WriteLine("Hello World!");
> Car c = new Car(null, "DD-AB-123", 4);
> InvalidValue[] invalidValues = validatorEngine.Validate(c);
> foreach (InvalidValue value in invalidValues)
> {
> Console.WriteLine("\t-Invalid Property: {0}. Error
> Message: {1}", value.PropertyName, value.Message);
> }
> }
>
>
>
> I also have file hibernate.cfg.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
> <session-factory name="NHibernate.Test">
> <property name="connection.driver_class">
> NHibernate.Driver.MySqlDataDriver</property>
> <property
> name="connection.connection_string">Server=localhost;Database=test;User
> ID=test;Password=test;</property>
> <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
> <property name="show_sql">true</property>
> </session-factory>
> </hibernate-configuration>
>
>
> And I'm using it just for a workaround for System I/O exception when this
> file is missing.
>
> But it throws exceptions like:
>
> Unhandled Exception:
> StackOverflowException
> Stack overflow in unmanaged: IP: 0x10ef2f4a2, fault addr: 0x7fff505a9ef0
>
>
> Unhandled Exception:
> StackOverflowException
> Stack overflow in unmanaged: IP: 0x7fff89c365ed, fault addr:
> 0x7fff505a8ff8
> [ERROR] FATAL UNHANDLED EXCEPTION: Nested exception detected.
> Original Exception: at (wrapper managed-to-native)
> System.RuntimeType.getFullName
> (System.RuntimeType,bool,bool) <IL 0x00033, 0x000ae>
> at System.RuntimeType.ToString () [0x00000] in /private/tmp/source-mono-
> 4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/
> mono-x86/mcs/class/corlib/ReferenceSources/RuntimeType.cs:599
> at System.Exception.GetClassName () [0x0000b] in /private/tmp/source-mono-
> 4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/
> mono-x86/mcs/class/referencesource/mscorlib/system/exception.cs:257
> at System.Exception.ToString (bool,bool) [0x00031] in /private/tmp/source-
> mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-
> root/mono-x86/mcs/class/referencesource/mscorlib/system/exception.cs:480
> at System.Exception.ToString () [0x00000] in /private/tmp/source-mono-4.6.
> 0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-
> x86/mcs/class/referencesource/mscorlib/system/exception.cs:466
>
>
> Nested exception:at string.FillStringChecked (string,int,string) [0x00000]
> in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/
> mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/
> system/string.cs:1499
> at string.Concat (string,string,string) [0x0005b] in /private/tmp/source-
> mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-
> root/mono-x86/mcs/class/referencesource/mscorlib/system/string.cs:3201
> at System.Exception.ToString (bool,bool) [0x00031] in /private/tmp/source-
> mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-
> root/mono-x86/mcs/class/referencesource/mscorlib/system/exception.cs:480
> at System.Exception.ToString () [0x00000] in /private/tmp/source-mono-4.6.
> 0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-
> x86/mcs/class/referencesource/mscorlib/system/exception.cs:466
>
>
> Could someone point me to doc which explain Configuration model in
> Hibernate? Why I need Configuration with any valid database for validator?
>
> Best
>
> Mikolaj
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.