Hello
I've hit same case lately. With "non null and not empty" constraint 
validation isn't even getting involved, NHibernate is throwing 
PropertyValueException on Save.
Stack trace: 
at NHibernate.Engine.Nullability.CheckNullability(Object[] values, 
IEntityPersister persister, Boolean isUpdate)
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate
(Object entity, EntityKey key, IEntityPersister persister, Boolean 
useIdentityColumn, Object anything, IEventSource source, Boolean 
requiresImmediateIdAccess)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(
Object entity, String entityName, Object anything, IEventSource source, 
Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveEventListener.
SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.
EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(
SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at 
NHibernate.Validator.Tests.Integration.UniquenessValidationUsingExternalValidatorFixture
.Should_throw_InvalidStateException() in ValidatingProxyFixture.cs: line 
292<about:projectfile%3A3B96A3A6-685A-43CF-B746-4F2EB69D2D49%2Fd%3AIntegration%2Ff%3AValidatingProxyFixture.cs%3F292%3F1>
 

Bellow is the code showing the problem. I would be creating a JIRA ticket, 
it looks like a bug for me. Or is it not the case?

A fixture that reproduces the problem (sorry for formatting, paste into 
Integration folder in tests ):

[TestFixture]
public class UniquenessValidationUsingExternalValidatorFixture : 
PersistenceTest
{
protected override void Configure(NHibernate.Cfg.Configuration 
configuration)
{
base.Configure(configuration);

var validatorConf = new FluentConfiguration();
validatorConf
.SetDefaultValidatorMode(ValidatorMode.UseExternal)
.IntegrateWithNHibernate
.ApplyingDDLConstraints()
.RegisteringListeners();

var vDefSimple = new ValidationDef<Relation>();
vDefSimple.Define(s => s.Description).NotNullableAndNotEmpty();
validatorConf.Register(vDefSimple);

var engine = new ValidatorEngine();
engine.Configure(validatorConf);
ValidatorInitializer.Initialize(configuration, engine);
}

[Test]
[ExpectedException(typeof(InvalidStateException))]
public void Should_throw_InvalidStateException()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
s.Save(new Relation());
tx.Commit();
}

CleanDb();
}

private void CleanDb()
{
using (var s = OpenSession())
using (var tx = s.BeginTransaction())
{
s.CreateQuery("delete from Relation").ExecuteUpdate();
tx.Commit();
}
}

protected override IList Mappings
{
get { return new[] {"Integration.SimpleWithRelation.hbm.xml"}; }
}
}


-- 
You received this message because you are subscribed to the Google Groups 
"NHibernate Contrib - Development Group" 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/nhcdevs?hl=en.

Reply via email to