jboss7.x - Mysql JPA throws javax.transaction.RollbackException: instead of ConstraintViolationException -


i using mysql & jpa on jobss7.1 astruts2 based application. use user transaction not cmt. catch constraintviolationexception when insert duplicate row table

the below code catches javax.transaction.rollbackexception not constraintviolationexception

            try {                   userdao=new userdaoimpl();                   initialcontext ic = new initialcontext();                   usertransaction  utx = (usertransaction) ic.lookup("java:comp/usertransaction");                   utx.begin();                   userdao.setem(em);                   userdao.saveconatact(contact);                   userdao.saveuser(user);                   utx.commit();                   return success;             }catch (exception e)             {               e.printstacktrace();               return error;             }          org.hibernate.exception.constraintviolationexception: duplicate entry 'john' key 'primary'             @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1361) [hibernate-entitymanager-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1289) [hibernate-entitymanager-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.ejb.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1295) [hibernate-entitymanager-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.ejb.abstractentitymanagerimpl$callbackexceptionmapperimpl.mapmanagedflushfailure(abstractentitymanagerimpl.java:1481) [hibernate-entitymanager-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.transaction.synchronization.internal.synchronizationcallbackcoordinatorimpl.beforecompletion(synchronizationcallbackcoordinatorimpl.java:109) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.transaction.synchronization.internal.registeredsynchronization.beforecompletion(registeredsynchronization.java:53) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ com.arjuna.ats.internal.jta.resources.arjunacore.synchronizationimple.beforecompletion(synchronizationimple.java:76)             @ com.arjuna.ats.arjuna.coordinator.twophasecoordinator.beforecompletion(twophasecoordinator.java:273)             @ com.arjuna.ats.arjuna.coordinator.twophasecoordinator.end(twophasecoordinator.java:93)             @ com.arjuna.ats.arjuna.atomicaction.commit(atomicaction.java:164)             @ com.arjuna.ats.internal.jta.transaction.arjunacore.transactionimple.commitanddisassociate(transactionimple.java:1165)             @ com.arjuna.ats.internal.jta.transaction.arjunacore.basetransaction.commit(basetransaction.java:117)             @ com.arjuna.ats.jbossatx.basetransactionmanagerdelegate.commit(basetransactionmanagerdelegate.java:75)             @ org.jboss.tm.usertx.client.servervmclientusertransaction.commit(servervmclientusertransaction.java:167)             @ com.action.registrationaction.createuser(registrationaction.java:66) [classes:]             @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) [rt.jar:1.7.0_55]             @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) [rt.jar:1.7.0_55]             @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) [rt.jar:1.7.0_55]             @ java.lang.reflect.method.invoke(unknown source) [rt.jar:1.7.0_55]             @ com.opensymphony.xwork2.defaultactioninvocation.invokeaction(defaultactioninvocation.java:450) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invokeactiononly(defaultactioninvocation.java:289) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:252) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.deprecationinterceptor.intercept(deprecationinterceptor.java:41) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.debugging.debugginginterceptor.intercept(debugginginterceptor.java:256) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.defaultworkflowinterceptor.dointercept(defaultworkflowinterceptor.java:167) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.validator.validationinterceptor.dointercept(validationinterceptor.java:265) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.validation.annotationvalidationinterceptor.dointercept(annotationvalidationinterceptor.java:68) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.conversionerrorinterceptor.intercept(conversionerrorinterceptor.java:138) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.parametersinterceptor.dointercept(parametersinterceptor.java:254) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.parametersinterceptor.dointercept(parametersinterceptor.java:254) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.staticparametersinterceptor.intercept(staticparametersinterceptor.java:191) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.multiselectinterceptor.intercept(multiselectinterceptor.java:73) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.checkboxinterceptor.intercept(checkboxinterceptor.java:91) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.fileuploadinterceptor.intercept(fileuploadinterceptor.java:252) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.modeldriveninterceptor.intercept(modeldriveninterceptor.java:100) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.scopedmodeldriveninterceptor.intercept(scopedmodeldriveninterceptor.java:141) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.chaininginterceptor.intercept(chaininginterceptor.java:145) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.prepareinterceptor.dointercept(prepareinterceptor.java:171) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.i18ninterceptor.intercept(i18ninterceptor.java:139) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.interceptor.servletconfiginterceptor.intercept(servletconfiginterceptor.java:164) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.aliasinterceptor.intercept(aliasinterceptor.java:193) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.interceptor.exceptionmappinginterceptor.intercept(exceptionmappinginterceptor.java:189) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:246) [xwork-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.impl.strutsactionproxy.execute(strutsactionproxy.java:54) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.dispatcher.dispatcher.serviceaction(dispatcher.java:562) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.dispatcher.ng.executeoperations.executeaction(executeoperations.java:77) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:99) [struts2-core-2.3.16.3.jar:2.3.16.3]             @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:280) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:248) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:275) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:161) [jbossweb-7.0.13.final.jar:]             @ org.jboss.as.jpa.interceptor.webnontxemcloservalve.invoke(webnontxemcloservalve.java:50) [jboss-as-jpa-7.1.1.final.jar:7.1.1.final]             @ org.jboss.as.web.security.securitycontextassociationvalve.invoke(securitycontextassociationvalve.java:153) [jboss-as-web-7.1.1.final.jar:7.1.1.final]             @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:155) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) [jbossweb-7.0.13.final.jar:]             @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:368) [jbossweb-7.0.13.final.jar:]             @ org.apache.coyote.http11.http11processor.process(http11processor.java:877) [jbossweb-7.0.13.final.jar:]             @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:671) [jbossweb-7.0.13.final.jar:]             @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:930) [jbossweb-7.0.13.final.jar:]             @ java.lang.thread.run(unknown source) [rt.jar:1.7.0_55]         caused by: org.hibernate.exception.constraintviolationexception: duplicate entry 'john' key 'primary'             @ org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:74) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:47) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:125) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:110) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.jdbc.internal.proxy.abstractstatementproxyhandler.continueinvocation(abstractstatementproxyhandler.java:129) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.jdbc.internal.proxy.abstractproxyhandler.invoke(abstractproxyhandler.java:81) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ com.sun.proxy.$proxy34.executeupdate(unknown source)             @ org.hibernate.engine.jdbc.batch.internal.nonbatchingbatch.addtobatch(nonbatchingbatch.java:56) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:2849) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.persister.entity.abstractentitypersister.insert(abstractentitypersister.java:3290) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.action.internal.entityinsertaction.execute(entityinsertaction.java:80) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.spi.actionqueue.execute(actionqueue.java:272) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.spi.actionqueue.executeactions(actionqueue.java:264) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.spi.actionqueue.executeactions(actionqueue.java:186) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.event.internal.abstractflushingeventlistener.performexecutions(abstractflushingeventlistener.java:326) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.event.internal.defaultflusheventlistener.onflush(defaultflusheventlistener.java:52) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.internal.sessionimpl.flush(sessionimpl.java:1081) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.internal.sessionimpl.managedflush(sessionimpl.java:315) [hibernate-core-4.0.1.final.jar:4.0.1.final]             @ org.hibernate.engine.transaction.synchronization.internal.synchronizationcallbackcoordinatorimpl.beforecompletion(synchronizationcallbackcoordinatorimpl.java:104) [hibernate-core-4.0.1.final.jar:4.0.1.final]             ... 79 more         caused by: com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: duplicate entry 'john' key 'primary'             @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) [rt.jar:1.7.0_55]             @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) [rt.jar:1.7.0_55]             @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) [rt.jar:1.7.0_55]             @ java.lang.reflect.constructor.newinstance(unknown source) [rt.jar:1.7.0_55]             @ com.mysql.jdbc.util.handlenewinstance(util.java:377)             @ com.mysql.jdbc.util.getinstance(util.java:360)             @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:971)             @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3887)             @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3823)             @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:2435)             @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:2582)             @ com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2530)             @ com.mysql.jdbc.preparedstatement.executeinternal(preparedstatement.java:1907)             @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2141)             @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2077)             @ com.mysql.jdbc.preparedstatement.executeupdate(preparedstatement.java:2062)             @ org.jboss.jca.adapters.jdbc.wrappedpreparedstatement.executeupdate(wrappedpreparedstatement.java:493)             @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) [rt.jar:1.7.0_55]             @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) [rt.jar:1.7.0_55]             @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) [rt.jar:1.7.0_55]             @ java.lang.reflect.method.invoke(unknown source) [rt.jar:1.7.0_55]             @ org.hibernate.engine.jdbc.internal.proxy.abstractstatementproxyhandler.continueinvocation(abstractstatementproxyhandler.java:122) [hibernate-core-4.0.1.final.jar:4.0.1.final]             ... 93 more 


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -