• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Validate Mapped Data from Database

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

when I pull a record from the database using Hibernate, is there a way to validate whatever is written into the domain object?

I am using field injection, as i am using a domain driven approach. now if let's say a field is required to be not null, how would i validate that after hibernate invokes the private no-arg constructor and injects all fields, that field really is not null?


thanks for your help

Sebastian
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you would most likely have a nullable = false constraint on your database column in that case right? It makes sense to enforce this on the database side and validate objects before inserting them. You should not have to worry in that case what comes out. But if you do have a look below:

If you are just looking at validating pojos you can have a look at the JSR-303 annotations. This is unrelated to the ORM hibernate but here is a library for validation.
http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic