이 코드는 my auditTrail 클래스의 일부로 사용하고 있지만 데이터베이스에 변경 사항을 기록하려고하면 stackOverFlow 예외가 발생합니다.Hibernate 인터셉터, 데이터베이스에 대한 감사 및 로깅
public void OnPostInsert(NHibernate.Event.PostInsertEvent @event)
{
if (!(@event.Entity is IAuditable))
{
using (ITransaction transaction = @event.Session.BeginTransaction())
{
if (@event.State != null)
{
for (int i = 0; i < @event.State.Length; i++)
{
string propertyName = @event.Persister.PropertyNames[i];
if (@event.State[i] != null)
{
if (@event.State[i].GetType().Namespace.StartsWith("Averma.Fda.Domain"))
{
CompareIfOldStateIsNull(@event.State[i], Convert.ToInt32(@event.Id), @event.Entity.GetType().ToString(), @event.Session, false);
}
else
{
string auditEntry = "New value for " + SplitPropertyName(propertyName) + " has been added, the new value is " + @event.State[i];
@event.Session.Save(new AuditTrail() { AuditEntry = auditEntry, RelatedEntityId = Convert.ToInt32(@event.Id), RelatedEntityType = @event.Entity.GetType().ToString(), OperationType = Shared.Enums.OperationType.Insert });
}
}
}
}
transaction.Commit();//the error occurs here
}
}
}
누구든지이 문제를 해결하는 방법에 대해 안내하고 데이터베이스에 변경 사항을 기록하는 방법을 알려주십시오.
'Averma.Fda.Domain'으로 시작하는 네임 스페이스가 아닌 것 같습니다. 따라서'else' 부분은'OnPostInsert'를 발생시키는'Insert'를 사용하는 것처럼 보이게됩니다. 네버 엔딩 스토리. 오히려 그것을 디버그하고 원치 않는 루프가 들어오는 곳을 확인해야합니다. 쉽게 찾을 수 있어야합니다. – C4u