Problema con Hibernate al borrar registro

fsiordia
30 de Mayo del 2009
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.AbstractFlushingEventListener performExecutions
GRAVE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
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.doInBackground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:278)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(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.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 21 more
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
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.doInBackground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:278)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(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.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.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.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
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.doInBackground(SWSingle.java:75)
at javax.swing.SwingWorker$1.call(SwingWorker.java:278)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:317)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(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!