java - Catching unique constraint exception in JSF -


i have column "name" in database unique constraint. i'm trying handle database exception, catch it, , return user friendly message user.

problem type of exception. cause of exception is

org.postgresql.util.psqlexception 

but when exception (top exception javax.ejb.ejbtransactionrolledbackexception) can't recognised psqlexception.

after research found that, , tried se why can't "psqlexception" put code this:

//code saving row database } catch (javax.ejb.ejbtransactionrolledbackexception e) {     try {         int = ((psqlexception)tisutil.getrooterror(e)).geterrorcode();         addmessagewarn("that name exists");     } catch (exception ex) {         addmessageerror(ex);     } }  

the goal see why java doesn't catch psqlexception. so, program goes section ejbtransactionrolledbackexception. getrooterror method finds root cause psqlexception, can't cast it.

exception ex looks this:

classcastexception", detailmessage: "org.postgresql.util.psqlexception cannot cast org.postgresql.util.psqlexception". 

i'm using jboss, wildfly 8.0, persistance 2.0, postgresql.

it looks you're using jta or ejb3 transaction management.

this defines layer on top of jdbc exceptions. cannot catch jdbc exceptions, because they're wrapped ejb3 exceptions. learn more, read ejb3, jta, , ejb transactions.

you must unwrap , inspect exceptions, java notably terrible at. tools apache exceptionutils lot, can walk down exception tree find particular exception class.

there's no guarantee psqlexception root; it's possible have java socket exception or root , psqlexception wrapping that.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -