-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem deleting a row with "ON DELETE RESTRICT"
PostPosted: Sat May 30, 2009 4:39 pm 
Newbie

Joined: Sat May 30, 2009 4:00 pm
Posts: 1
hi im new here and new with hibernate.... i have this problem..

i have a MySQL DB witha table named "area" with a "ON DELETE RESTRICT", and, when i try to delete a row, the app crash with the next message: "WARNING: SQL Error: 1451, SQLState: 23000" because the DB dont allow that...

here, the stacktrace:
Code:
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)



And here the mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<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>




Thanks!


Top
 Profile  
 
 Post subject: Re: Problem deleting a row with "ON DELETE RESTRICT"
PostPosted: Mon Jun 20, 2011 6:01 am 
Newbie

Joined: Mon Jun 20, 2011 5:55 am
Posts: 1
I have exactly the opposite problem : I NEED to have that exception when someone tries to delete a row that is related to others with foreign keys set to ON DELETE RESTRICT. I guess that I have to change the hbm file (maybe the "cascade" option) but googling I haven't found how to solve this. Can somebody help me? Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.