hola, soy nuevo en el foro.. espero alguein me peuda ayudar.. tengo un problema q por mas q busco como solucionarlo no encuentro como...
tengo una BD MySQL y mi aplicacion de java usa hibernate... la BD tiene una tabla que es Area que tiene un ON DELETE RESTRICT para poder conservar correctamente las relaciones. El problema esta que cuando el usuario intenta borrar un registro de esta tabla que tiene alguna relacion, la base de datos no se lo permite pues causa un "SQL Error: 1451, SQLState: 23000" lo que hace que la aplicacion se cierre...
Les dejo el stacktrace del error:
30/05/2009 02:50:40 PM org.hibernate.util.JDBCExceptionReporter logExceptions
ADVERTENCIA: SQL Error: 1451, SQLState: 23000
30/05/2009 02:50:40 PM org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Cannot delete or update a parent row: a foreign key constraint fails (`calakmul/puesto`, CONSTRAINT `area_puesto` FOREIGN KEY (`idarea`) REFERENCES `area` (`idarea`) ON UPDATE CASCADE)
30/05/2009 02:50:40 PM org.hibernate.event.def.AbstractFlushingEventListe ner performExecutions
GRAVE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListe ner.onAutoFlush(DefaultAutoFlushEventListener.java :41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired (SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 9)
at calakmul.logica.Area.getLista(Area.java:33)
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:64 )
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:60 )
at com.amarello.ui.interfaz.adapter.SWSingle.doInBack ground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:27 8)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`calakmul/puesto`, CONSTRAINT `area_puesto` FOREIGN KEY (`idarea`) REFERENCES `area` (`idarea`) ON UPDATE CASCADE)
at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
... 21 more
org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListe ner.onAutoFlush(DefaultAutoFlushEventListener.java :41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired (SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 9)
at calakmul.logica.Area.getLista(Area.java:33)
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:64 )
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:60 )
at com.amarello.ui.interfaz.adapter.SWSingle.doInBack ground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:27 8)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`calakmul/puesto`, CONSTRAINT `area_puesto` FOREIGN KEY (`idarea`) REFERENCES `area` (`idarea`) ON UPDATE CASCADE)
at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
... 21 more
Caused by
java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`calakmul/puesto`, CONSTRAINT `area_puesto` FOREIGN KEY (`idarea`) REFERENCES `area` (`idarea`) ON UPDATE CASCADE)
at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListe ner.onAutoFlush(DefaultAutoFlushEventListener.java :41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired (SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 9)
at calakmul.logica.Area.getLista(Area.java:33)
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:64 )
at calakmul.interfaz.AreaPanel$1.db(AreaPanel.java:60 )
at com.amarello.ui.interfaz.adapter.SWSingle.doInBack ground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:27 8)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:637)
Ahora les dejo el mapeo de la tabla:
<hibernate-mapping>
<class name="calakmul.logica.Area" table="area">
<id column="idarea" name="id" type="integer" unsaved-value="0">
<generator class="native"/>
</id>
<property column="nombre" name="nombre" not-null="true" type="string"/>
</class>
</hibernate-mapping>
No encuentro la manera de cachar la excepcion que el hibernate lanza....
Se que de alguna manera hibernate debe tener alguna manera de manejar esto.
espero su ayuda... y de antemano gracias!