• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA 2.0/EclipseLink how to access "internal exception" type?

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've added a unique constraint to a table as follows:

My entity:


I then catch the exception in my EJB method create():

My EJB:


I then try to add "John Doe" twice, triggering a PersistenceException to be thrown by persist(). In my
server log I can see that there is an internal exception thrown MySQLIntegrityConstraintViolationException,
as you'd expect:



The problem is that I don't know how to access this internal level of detail about the exception, all I know
is that there is a PersistenceException, not that there's been a MySQLIntegrityConstraintViolationException.

At present my code handles an integrity constraint violation in exactly the same way as if I've forgotten
to start the database server, what I want to do is to separate out "soft" errors related to user input from
hard errors such as coding errors and major environmental problems.

If anyone knows how to achieve this I'll be eternally grateful.

Thanks,
Brendan.
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can pretty much answer by own question now I think, the key point being that the exceptions are chained,
and you can navigate through the list to the root exception which is MySQLIntegrityConstraintViolationException.



And there you have it.

Regards,
Brendan.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also had to get to the root MySQLIntegrityContraintViolationException. I like your concise for loop, however it needed a minor correction:

As you had it, the the variable t is always null when the for loop returns.
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic