Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Best practice for enforcing business rules on entity objects?

 
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
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic