Hi Markus, thanks for a quick reply,
I've faced a problem with not expected session flushing during the
following scenario:
1. I get entity from database
2. Update some properties
3. Query database to get another entity (to set up BelongsTo
association)
and at this point FindAll flushes the session with changes from the
step 2 (seems that NHibernate does that).
Here is a code example:
[Test]
public void
should_not_flush_invalid_objects_while_querying_database_in_transaction_scope
()
{
using (new TransactionScope())
{
// FirstName is NotNull = true
var person = new Person {FirstName = "name"};
ActiveRecordMediator<Person>.Save(person);
}
using (new TransactionScope())
{
var person = ActiveRecordMediator<Person>.FindFirst();
person.FirstName = null;
// query for another entity throws an excpetion
ActiveRecordMediator<Country>.FindAll().Count();
}
}
And here is the stack trace:
NHibernate.PropertyValueException: not-null property references a null
or transient
valueScalepoint.EasyClaims.Common.Core.Models.Person.FirstName
at NHibernate.Engine.Nullability.CheckNullability(Object[] values,
IEntityPersister persister, Boolean isUpdate)
at
NHibernate.Event.Default.DefaultFlushEntityEventListener.ScheduleUpdate
(FlushEntityEvent event)
at
NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity
(FlushEntityEvent event)
at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities
(FlushEvent event)
at
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions
(FlushEvent event)
at NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush
(AutoFlushEvent event)
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList
results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List()
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order
[] orders, ICriterion[] criteria)
Castle.ActiveRecord.Framework.ActiveRecordException: Could not perform
FindAll for Country
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order
[] orders, ICriterion[] criteria)
at Castle.ActiveRecord.ActiveRecordMediator.FindAll(Type targetType,
Order[] orders, ICriterion[] criterias)
at Castle.ActiveRecord.ActiveRecordMediator.FindAll(Type targetType)
at Castle.ActiveRecord.ActiveRecordMediator`1.FindAll()
at
Tests.Integration.Verification.ActiveRecordTests.should_not_flush_invalid_objects_while_querying_database_in_transaction_scope
() in ActiveRecordTests.cs: line 108
On Aug 13, 4:04 pm, Markus Zywitza <[email protected]> wrote:
> You don't have to. Using the default flushing behaviour, TransactionScopes
> don't flush unless they are committed and disposed.
>
> -Markus
> 2009/8/13 vitalya <[email protected]>
>
>
>
> > Hello Everyone,
>
> > I've got a question, how do I create a TransactionScope with
> > FlushAction.Never? the problem is, that there is no overloaded
> > constructor, and currently the only option available, is to use
> > configuration, as far as TransactionScope constructor defines a
> > default value FlushAction.Config.
> > Is there a reason, to create a patch with overloaded constructor?
>
> > Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---