Hi,
I think NH is not ignoring Transient Object from refreshing. trying to
refresh transient object obviously throws assertion exception..
i solved the issue by creating EventListener on refresh with following
code
public class EntityRefreshEventListener : IRefreshEventListener
{
DefaultRefreshEventListener defaultListener = new
DefaultRefreshEventListener( );
public void OnRefresh(RefreshEvent @event,
System.Collections.IDictionary refreshedAlready)
{
if (IsPersistantObject(@event))
{
defaultListener.OnRefresh(@event, refreshedAlready);
}
}
private static bool IsPersistantObject(RefreshEvent @event)
{
return @event.Session.Contains(@event.Entity) &&
@event.Session.GetIdentifier(@event.Entity) != null;
}
public void OnRefresh(RefreshEvent @event)
{
defaultListener.OnRefresh(@event);
}
}
On Dec 29, 6:20 pm, Davy Brion <[email protected]> wrote:
> does it still occur when you add con.Customer = c before the call the
> session.Refresh(c)?
>
> you're required to keep both ends of the relationship in sync, which is why
> most people add specialized methods like AddContact which would add the
> contact to the customer's contacts collection _and_ would also set up the
> other end of the relationship (contact's Customer property)
>
>
>
> On Tue, Dec 29, 2009 at 7:52 AM, PVM <[email protected]> wrote:
> > Hi
>
> > i have an object Customer with Contact as a list property. pseudo code
> > is like
>
> > Customer c = new Customer()
>
> > Contact con = new Contact()
>
> > c.ContacltList.Add(c);
>
> > when i ask refresh entity by calling session.Refresh(c)
>
> > throwing exception
>
> > stacktrace
>
> > Type : NHibernate.AssertionFailure, NHibernate, Version=2.1.2.4000,
> > Culture=neutral, PublicKeyToken=aa95f207798dfdb4
> > Message : null identifier
> > Source : NHibernate
> > Help link :
> > Data : System.Collections.ListDictionaryInternal
> > TargetSite : Void .ctor(System.Object, System.String, System.String,
> > NHibernate.Type.IType, Boolean,
> > NHibernate.Engine.ISessionFactoryImplementor, NHibernate.EntityMode)
> > Stack Trace : at NHibernate.Engine.EntityKey..ctor(Object
> > identifier, String rootEntityName, String entityName, IType
> > identifierType, Boolean batchLoadable, ISessionFactoryImplementor
> > factory, EntityMode entityMode)
> > at NHibernate.Engine.EntityKey..ctor(Object id, IEntityPersister
> > persister, EntityMode entityMode)
> > at NHibernate.Event.Default.DefaultRefreshEventListener.OnRefresh
> > (RefreshEvent event, IDictionary refreshedAlready)
> > at NHibernate.Impl.SessionImpl.FireRefresh(IDictionary
> > refreshedAlready, RefreshEvent refreshEvent)
> > at NHibernate.Impl.SessionImpl.Refresh(Object obj, IDictionary
> > refreshedAlready)
> > at NHibernate.Engine.CascadingAction.RefreshCascadingAction.Cascade
> > (IEventSource session, Object child, String entityName, Object
> > anything, Boolean isCascadeDeleteEnabled)
> > at NHibernate.Engine.Cascade.CascadeToOne(Object child, IType type,
> > CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
> > at NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType
> > type, CascadeStyle style, Object anything, Boolean
> > isCascadeDeleteEnabled)
> > at NHibernate.Engine.Cascade.CascadeProperty(Object child, IType
> > type, CascadeStyle style, Object anything, Boolean
> > isCascadeDeleteEnabled)
> > at NHibernate.Engine.Cascade.CascadeCollectionElements(Object
> > child, CollectionType collectionType, CascadeStyle style, IType
> > elemType, Object anything, Boolean isCascadeDeleteEnabled)
>
> > can any one help on understanding why this is happening and solution?
>
> > --
>
> > 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.
--
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.