• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding null values

 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have some attributes in a class which map to columns in the database. The column which it maps to may be not null. Is there any way without doing an insert to know which values are null ? I want to avoid an extra trip to the database to find out on which column it blew up ?

Thanks

-Harjit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If in your mapping you map those fields as Not Null, Hibernate will check the Objects first before sending them to the database, so what you are looking for is actually built in to Hibernate. If you have a null value in the object for a not null field, then Hibernate will throw an Exception without sending any statements to the database.

Good Luck

Mark
 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to do an insert or a save to find that out. There is a better way which I found using Hibernate Validator, What that does is actually a dry run of your whole operation. You can also use annotations on various members and specify their length ,min,max and all other stuff related to attributes.

Thanks

- Harjit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic