• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How handle rollbackexceptions in Java Persistence

 
Daniel Näslund
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this model:


and this method in my DAO


If I were to supply a Day object with a comment field set to null I would get a RollbackException. What to do? Handle, throw or stop before it reaches the persistence layer?

Throw a NullpointerException or IllegalArgumentException was my first thought but perhaps there is some smart way to use the RollbackException... The question is really, where should the validation take place?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd bubble it up and allow the component calling the method , or even a method higher on the stack, handle the unchecked exception

-Cameron McKenzie
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Catching here the exception would not have much sense since for business purposes the error is meaningless. At a higher level could have meaning and could take a decision on how to procede further on that.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. I mean, if it's rolled back, it's rolled back, right?

-Cameron McKenzie
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic