Saturday, April 12, 2008

Track down TransientObjectException

Problem:

TransientObjectException is hibernate (nhibernate in my little world) exception which occurs when you flush.

Identify the code which causes it:

It is simple. Put nhibernate session.IsDirty() underwatch. Execute your program stpe by step. You are 'ok' till IsDirty give you 'true' or 'false'. You can identify the culprit step when IsDirty raises any exception.

Cause and Solution:

No one can you tell you exact solution as this may be caused by variety of mistakes. The root cause is that you are trying to save an object into database which has transient objects (not existing in database in our context) attached to it. Solution is to save the transient objects before flush or just remove the "cascade" attribute from the HBM.