Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practice for enforcing business rules on entity objects?

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have started working on a new application which uses Spring and Hibernate for the data layer. I want to enforce business rules on my entity objects before they are saved in order to ensure that my database stays free of invalid data. On a previous project I worked on (different employer so I can't reuse the code) there was a mechanism in place in which you could write business rules for entity objects and before an entity object was saved, updated, or deleted it was checked against the applicable business rules before the operation was allowed to proceed. This business rule processing system was not trivial and I'm afraid that I'm not up to the task of writing such a system myself so I'm hoping that something exists which will do this for me. (I'm not even sure what the term for such a system would be, which makes it difficult to find something appropriate using Google!)

As an example of what I'm talking about let's say I have an entity class representing a machine on a network, and one of its fields is a String for the machine's IP address. What I'd like to have is a business rule that is run against the entity before it is saved or updated which checks the IP address field to make sure that it's a valid IP address. So if I create a new machine entity and give the IP address field a value of "345.4567.2.35" then a save would fail since the IP address field is not in a valid IP address format.

Can anyone suggest the best practice for handling this sort of problem? Are there any open source solutions available that I could take advantage of or will I have to cook up something myself? Thanks in advance for any suggestions!

--James
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found Hibernate Validator which appears to be the answer to my problems.

http://www.hibernate.org/hib_docs/validator/reference/en/html/index.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic