---
title: "DB constraint violation details from EJBException"  
description: "DB constraint violation details from EJBException"  
author: "Anonymous User"  
published: 2013-06-12  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1047/db-constraint-violation-details-from-ejbexception  
category: "java"  
tags: ["java"]  
reading_time: 3 minutes  

---

# DB constraint violation details from EJBException

```
@ManagedBean(name = "bookingController")@SessionScopedpublic class BookingController implements Serializable {...    public String update() {        try {            getFacade().edit(current);            recreateModel();            JsfUtil.addSuccessMessage("Booking Update successful");            return "booking";        } catch (Exception e) {            JsfUtil.addErrorMessage("[" + e.getClass().getCanonicalName() +                "] " + e.getLocalizedMessage());            serviceLogger.error("Booking not
modified; reason: ",e);            return null;        }    }...}
```

An app is deployed on Glassfish 3.1.1. When [editing](https://www.mindstick.com/startup/27/photoroom-the-ai-powered-app-transforming-photo-and-video-editing) data in the form I enter a [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) value in one of the [fields](https://www.mindstick.com/forum/159126/sql-query-for-all-tables-and-fields-in-an-oracle-db), which violates [unique constraint](https://www.mindstick.com/forum/159036/how-can-i-create-a-unique-constraint-that-also-allows-nulls) in the table. When submitting the form I get:

```
[javax.ejb.EJBException] Transaction abortedas a JSF message (which means nothing to end user), andERROR 2012-04-10 17:33:54,199 - Booking not modified; reason: javax.ejb.EJBException: Transaction aborted    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5120)    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)    at $Proxy963.edit(Unknown Source)    at tp.coma.cint.data.beans.__EJB31_Generated__BookingsFacade__Intf____Bean__.edit(Unknown Source)    at tp.coma.cint.jsf.BookingController.update(BookingController.java:166)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    at java.lang.reflect.Method.invoke(Method.java:597)    at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)    at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)    at com.sun.el.parser.AstValue.invoke(AstValue.java:228)    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43)    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56)    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)    at javax.faces.component.UICommand.broadcast(UICommand.java:315)    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)    at java.lang.Thread.run(Thread.java:662)Caused by: javax.transaction.RollbackException: Transaction marked for rollback.    at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:473)    at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:852)    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5114)    ... 54 moreCaused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseExceptionInternal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '111222-0' for key 2Error Code: 1062Call: UPDATE Booking SET bk_cnum_user = ?, bk_title = ? WHERE (bk_id = ?)    bind => [3 parameters bound]Query: UpdateObjectQuery(tp.coma.cint.data.entities.Bookings[ bkId=22 ])    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:840)    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:592)    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)    at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253)    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.updateObject(DatasourceCallQueryMechanism.java:749)    at org.eclipse.persistence.internal.queries.StatementQueryMechanism.updateObject(StatementQueryMechanism.java:432)    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1042)    at org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)    at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:287)    at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)    at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:728)    at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)    at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1443)    at org.eclipse.persistence.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:265)    at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:128)    at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3784)    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1407)    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:634)    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1497)    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3135)    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:344)    at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)    at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)    at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:435)    ... 56 moreCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '111222-0' for key 2    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)    at com.mysql.jdbc.Util.getInstance(Util.java:384)    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2409)    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)    at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:877)    at com.sun.gjc.spi.base.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:125)    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:831)    ... 88 more
```

\

in the log.

My [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) is: how to discover which table, [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) and value caused the [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) to make a [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) much more clear to the user?

## Replies

### Reply by Vijay Shukla

Hello Jeet Verma!\
\
I use hibernate and enable parameter logging to debug things like this. I found you can do the same with eclipselink logging, then you could see what values are the problem. Set this in your persistence.xml:\
<property name="eclipselink.logging.parameters" value="true"/>


---

Original Source: https://www.mindstick.com/forum/1047/db-constraint-violation-details-from-ejbexception

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
