These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Interceptor update generates update on delete - evict?
PostPosted: Wed Oct 22, 2008 8:48 am 
Newbie

Joined: Wed Aug 06, 2008 2:43 am
Posts: 2
Hibernate version: 1.2.1.4000

Hi,

I have an intercepter that timestamps the objects in my database. It works fine for update and create, but with deletes the update of the timestamp generates an update when the session is completed.

If i remove the line ending with // HERE below, OnFlushDirty is not called when the session completes.

Nhibernate must think of the update of the timestamp as an update to the object. I am using this.session.FlushMode = FlushMode.Never, so why does nhibernate try to persist the object, when i havent called .saveorupdate/save/update on the object?

(the reason for updating the deleted object is, as it can be seen that it used for telling the clients when the delete occoured)

I thought that maybe evicting the object after deleting it would make nhibernate not want to try and persist the object on flush, but this causes an exception:

NHibernate.AssertionFailure: possible nonthreadsafe access to session
at NHibernate.Impl.SessionImpl.PostDelete(Object obj)
at NHibernate.Impl.ScheduledDeletion.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at ....Repository.OperationSession.Complete

the interceptor code:

public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
UpdateTimestamp(entity, propertyNames, state); // HERE
eventDispatcher.AddChangeHint(new ChangeHint(ChangeType.Delete, (IDomainObject) entity));
}

private static void UpdateTimestamp(object entity, string[] propertyNames, object[] state)
{
DomainObject domainObject = entity as DomainObject;
if (domainObject != null)
{
int index = Array.IndexOf(propertyNames, "Timestamp");
if (index >= 0)
{
state[index] = DateTime.UtcNow;
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 3:36 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
This has been a problem for a long time. We were able to work around it by returning int[0] from IInterceptor.FindDirty() when the entity is marked for deletion, but to know that we had to add non-persisted boolean property for it on our entity base class.

The problem should be entered in JIRA, since many people won't want to do what we did ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.