I didn't want to file a jira issue until I was sure this was actually an issue (which I'm pretty sure it is). It seems that update scenarios were failing under all of my persistance unit tests. After debugging, I found the following two issues.
First off, the PersistentObjectException always seemed to be firing. RequestedId has a type of object, but seems to always turn out to be bool. When checking for null, it seemed for some reason that my debugger was skipping over it because the bool was true. For this reason, I added the boolean check and fixed that problem.
Code:
DefaultSaveOrUpdateEventListener.cs - starting line 96
ISessionFactoryImplementor factory = @event.Session.Factory;
object requestedId = @event.RequestedId;
object savedId;
if (requestedId == null || (requestedId is bool && (bool)requestedId == true))
{
savedId = entityEntry.Id;
}
else
{
if (!entityEntry.Persister.IdentifierType.IsEqual(requestedId, entityEntry.Id, EntityMode.Poco))
{
throw new PersistentObjectException("object passed to save() was already persistent: " +
MessageHelper.InfoString(entityEntry.Persister, requestedId, factory));
}
savedId = requestedId;
}
if (log.IsDebugEnabled)
{
log.Debug("object already associated with session: " +
MessageHelper.InfoString(entityEntry.Persister, savedId, factory));
}
return savedId;
Problem #2 came shortly after. SaveOrUpdate in cascading scenarios would pass the proxy object to the following method with obj.GetType() obviously failing at GetClassPersister. Thus the following updates were needed.
Code:
SessionImpl.cs
public override IEntityPersister GetEntityPersister(object obj)
{
System.Type type = obj.GetType();
if (obj is INHibernateProxy)
{
type = ((INHibernateProxy)obj).HibernateLazyInitializer.PersistentClass;
}
return GetClassPersister(type);
}
I've noticed the updates to the trunk have been very frequent and I wasn't sure if you guys were having these issues? So far, I've found the trunk VERY stable till this issue which was pretty minor to fix. Please let me know if you want this filed under jira.