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?

Answers


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

Why creating a variable of a type “IEnumerable<MyClass> myVar” doesn't need a NEW keyword?

c# class object ienumerable

If we have written a class called MyClass and need an object of it's type, we would go

How to highlight the entire map using svg in HTML file?

javascript html map svg mouseover

this is coding for map. If i mouse over the map it highlight only half of the state is displayed. i need to highlight the full state. How to do it? can anyone help me with codings...

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.