Aug 24th, 2008, 08:47 PM
dirty hibernate session causes update during spring validation
I am using Spring 1.2.8 and Hibernate 3 and have the following problem:
In my web application there is a page where it is possible to edit some entities. The user chooses an entity to edit the property "name" (String) and submits the form when done. In the validator of the form I would like to test if the property "name" of the entity is unique, before the change is persisted to MySQL. But every time the query (which checks whether the property "name" of the entity is unique or not) is executed, hibernate updates the data in the MySQL table, no matter whether the validation fails afterwards or not. Is there a nice way to run a hibernate SELECT query whithout the UPDATE of dirty objects is triggered?
Thank you and sorry for my english
Last edited by dumbi; Aug 27th, 2008 at 07:08 AM.
Jan 1st, 2010, 03:15 PM
Hello everyone! I am still having this problem. Please help!
May 3rd, 2010, 01:01 PM
Could you attach your config files, model objects, and form controller? It's pretty hard to diagnose a problem without any point of reference.
May 3rd, 2010, 01:49 PM
I just went through this. Here are your options:
1) Throw a business error if validation fails then catch this error on the web side of the code.
2) do the validation in the webui and dont let it get to the business code.
3) Evict the entity before it gets into your service method.
4) Have a delegate layer that does validation and if it passes call the transactional service.
5) Use a dto not a hibernate object on your form that way you dont dirty your loaded hibernate object.
There are some other options as well but this could get you started. I did something similar to number 4.
Tags for this Thread