Hibernate get old / new for audit log

I want to log the changes of some entities. so I'm using onflushdirty of hibernate interceptor.

but the previous states is always empty or null

after some search I found 2 ways to get the old/previous values:

1- open a new temp session and find the bean again

2- in order to have the previousStates[] not empty I have to use merge instead of save/update. (actually unsure if this is true and don't know what will happen with the actual system's behavior...)

is there any other better way to do that?


If you are just calling update with an object that you have created the previous state will be empty. You should load / get the object first and then change its properties (in our regular code not in the interceptor), on doing this you will get the previous state. Merge achieves the same thing.

Need Your Help

SQL Server backup collation issue

sql sql-server sql-server-2008 collation

I was given SQL Server 2005 backup with collation set to : SQL_Latin1_General_CP1_CI_AI

Finding the File Version of a COM DLL using ASP.NET

asp.net com

I have a software diagnostic page on which I would like to list the File Version information of a couple of COM DLLs. The page is running under the normal, restricted ASP.Net account (NETWORK SERVI...

asp.net mvc without pre-compiling

asp.net-mvc asp.net-mvc-3

When I make changes to controllers in MVC I have to re-compile and upload my binaries for the changes to be noticed on my website. This makes sense, but I was wondering is there a way (or some sett...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.