I am developing a system with the Spring Framework and Hibernate and I am using the DAO Pattern to abstract my data access code. Something that seems odd to me is the transparent persistance mechanism of hibernate. It seems to be making my DAO obsolete on edits. Here is what I mean:
Code:
ClientDAO dao = new DefaultClientDAO() ;
Client client = dao.getClientFromId(1) ;
client.setName("New Name") ;
// this call doesn't appear to be necessary
dao.store(client) ;
The above code poses a problem if the name that is set is invalid. Let say I have a ClientValidator object that makes sure the edits to the client object meet the system requirements, it would be to late at this point because the value would be stored to the db before the validator even gets to it.
Any suggestions on a solution? Or if I am way off on how things work with Hibernate please give me some direction.
Thanks