hi all, i have a web form 2.0 application.

i have this 3 classes

[ParentIsValid]
Parent
{
long ID,
string Name,
Target Target,//many-to-one
Child Child //1-to-many cascade-all
}

Target
{
long ID
}

Child
{
long ID
}

and this validator

//specif validatot of parent istance to check that Name-Target.Id is
unique
ParentIsValidAttribute : Attribute, IRuleArgs, IValidator
{
   Message {get;set;}

   public NotEqualsToAttribute(object value, params object[] values)
   {
      //if value is Parent, return valid if not exists another Parent
with the same Name and Target.Id
          //the check is made with a named hql query
   }
}

i have integrate the validator with nhibernate so at commit it will
validate all the istances.

my web page do this things

OnInit -> bind session and begin nh tx.
OnButtonClick -> save a new Child, save a new Parent(which references
the child)
OnPreRenderComplete -> commit the tx., unbind and close/dispose the
session

my problem is that there's a database exception on commit becouse
hibernate tries to inser twice the same Child istance.

this is the stack (the inner exception is about the violation of the
unique constraint on child.id)

Exception of type 'could not insert: [Child#1619][SQL: INSERT INTO
child (id) VALUES (?)]'

   at
NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id,
Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql,
Object obj, ISessionImplementor session)
   at
NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id,
Object[] fields, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource
session)
   at
NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent
event)
   at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1
querySpaces)
   at NHibernate.Impl.SessionImpl.List(String query, QueryParameters
queryParameters, IList results)
   at NHibernate.Impl.SessionImpl.List(String query, QueryParameters
parameters)
   at NHibernate.Impl.QueryImpl.List()
   at NHibernate.Impl.AbstractQueryImpl.UniqueResult[T]()
   at MyCode.ParentRep.ExistsByNameAndTarget(String name, Int64
targetId)
   at MyCode.ParentIsValidValidatorAttribute.IsValid(Object value,
IConstraintValidatorContext constraintValidatorContext)
   at
NHibernate.Validator.Engine.ClassValidator.<>c__DisplayClass24.<EntityInvalidValues>b__1d(<>f__AnonymousType2`2
<>h__TransparentIdentifier19)
   at
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at NHibernate.Validator.Engine.ValidatorEngine.Validate(Object
entity, Object[] activeTags)
   at NHibernate.Validator.Event.ValidateEventListener.Validate(Object
entity, EntityMode mode)
   at
NHibernate.Validator.Event.ValidatePreInsertEventListener.OnPreInsert(PreInsertEvent
event)
   at NHibernate.Action.EntityInsertAction.PreInsert()
   at NHibernate.Action.EntityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource
session)
   at
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
event)
   at NHibernate.Impl.SessionImpl.Flush()
   at NHibernate.Transaction.AdoTransaction.Commit()
   at MyCode.NhBasePage.Commit()
   at MyCode.NhBasePage.OnPreRenderComplete(EventArgs e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

i'm doing samething wrong or i must open a jira?

-- 
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.

Reply via email to