Search code examples
hibernatejpatransactionstransient

In Hibernate JPA; even after I am committing transaction; the transient variables values are intact


I have an entity; which has transient variables. After I commit this entity; I thought that when next time I do any operation on this entity ( without jvm restart like an update on entity) ; those transient values will be reset to null but its not happening so.

What is the best practice ; so that after transaction is committed ( actually even roll back ) successfully ; all transient values are reset.. I know I can explicitly do that; but I am looking for best practice to do so.


Solution

  • The persistence layer isn't going to touch the transient values (that's why you made them transient, right?) so they will only go away when the object is garbage collected. You could probably force the issue by evicting the entity from the JPA cache (or making it non-cacheable) and fetching it again. I guess another option would be to explicitly clear the transient values in your data access layer.