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

Hibernate Validation on Update

 
Annie Harris
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have an EJB session bean that is managing my hibernate transactions.

When I insert a new record

try {
session.save(newRecord);
} catch (ConstraintViolationException e) {

}
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither the topic of the post nor its contents mention what you are looking for? Please specify more details as to what you are trying to do.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I think it is a Hibernate question, so I am moving this to the ORM forum. Please also give us more detail, what is your question? Or are you getting an Error?

Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Annie Girl",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Annie Harris
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I'll try again...

Hi all,
I have J2EE appplication running on JBoss 4.0.3. It is using a Hibernate MBean & using a Session bean to manage the hibernate transactions.

When I create a new record, the database constraints (e.g. unique name) can be caught & dealt with (with the purpose of presenting a readable message to the user):

try { session.save(newRecord); }
catch (ConstraintViolationException e) { // deal with it }

When I update an existing record, the exception isn't caught in the same manner:

try { session.update(existingRecord); }
catch (ConstraintViolationException e) { // exception not thrown }

It is only when the record is persisted to the DB that org.jboss.tm.JBossRollbackException with a nested throwable: (org.hibernate.exception.ConstraintViolationException) is thrown.

How do I can configure hibernate to validate the constraints before it reaches the db so that I can deal with the update save & update in the same manner?

Thanks,
Annie
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic