Hi,
I'd like to catch this kind of Exception (duplicate key on unique index) because in this case my Application must have a special behavior. I don't know how I can recognize this error and catch it. Another problem is that my application will be installed with different databases (MS SQL Server or Oracle or DB2 ect.) and I'd like to write "generic" code....
Anyone can help me?
I'm sorry for my bad bad English!!!!
Bye,
Sara
Hibernate version:
2.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
tx = session.beginTransaction();
log.debug("SAVE_OR_UPDATE --> "+po);
session.saveOrUpdate(po);
commitTransaction(tx);
Full stack trace of any exception that occurs:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert duplicate key row in object 'FDIPEND' with unique index 'uniq_cdutente'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.C3P0PreparedStatement.executeUpdate(C3P0PreparedStatement.java:68)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:683)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:633)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2262)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.sinapsi.share.persistance.hibernate.HibernateSessionManager.commitTransaction(HibernateSessionManager.java:133)
at com.dm.dao.AbstractDAO.commitTransaction(AbstractDAO.java:230)
at com.dm.dao.AbstractDAO.saveOrUpdate(AbstractDAO.java:161)
Name and version of the database you are using:
MS SQL SERVER 2000
The generated SQL (show_sql=true):
STATEMENT --> update FDIPEND set NMCOGNOME= 'FRATTINI' , IDAZIENDA= 4 , IDCODSEL1= '' , NMNOME= 'FRANCESCA' , IDUTENTEVALID= '' , IDUTENTEMOD= '' , CDFISCAL= 'FRTFNC96R52E730L' , IDCODSEL2= '' , IDSDIC= '0' , CDDIPENDENTE= '5' , IDCODSEL3= '' , IDRICHIESTA= 2 , TXPASSWORD= '554113e3cbedbc9aff' , CDPAGA= '' , TXMAIL=
'SFRATTINI@DATAMANAGEMENT.IT' , FLBENVENUTO= '0' , CDUTENTE= 'LLRBBR75A62H199I' , DTCREAPWD= '' , DTLASTLOGIN= '' , TXULTPWD1= '' , TXULTPWD2= '' , TXULTPWD3= '' , TXULTPWD4= '' , FLREVOCA= '' where ID= ''
Debug level Hibernate log excerpt: