-->
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.  [ 3 posts ] 
Author Message
 Post subject: java.sql.BatchUpdateException: Cannot delete
PostPosted: Thu Mar 02, 2006 9:19 am 
Newbie

Joined: Wed Feb 22, 2006 2:15 am
Posts: 10
String accounts[] = deletedAccounts.split(",");

for (int i=0; i<accounts.length; i++)
{
AccountImpl account = (AccountImpl) sess.load(AccountImpl.class, accounts[i]);
sess.delete (account);
sess.flush();
}

When I try to delete account I get the following exception :

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:74)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:150)
at org.hibernate.persister.entity.BasicEntityPersister.delete(BasicEntityPersister.java:2049)
at org.hibernate.persister.entity.BasicEntityPersister.delete(BasicEntityPersister.java:2213)
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:59)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.apache.jsp.adsales.masterdatamgmt.accounts_jsp._jspService(org.apache.jsp.adsales.masterdatamgmt.accounts_jsp:255)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:831)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1203)
at java.lang.Thread.run(Unknown Source)

Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:822)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)




I think it is due to foreign key relationship.

My mapping file is as follows :


<?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
auto-import="false"
>
<class
name="com.uniken.adsalesentities.AccountImpl"
table="Account"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
>

<id
name="accountName"
column="accountName"
type="java.lang.String"
unsaved-value="null"
>
<generator class="assigned">
</generator>
</id>

<property
name="accountCode"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="accountCode"
/>

<property
name="accountStatus"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="accountStatus"
/>

<property
name="agency"
type="boolean"
update="true"
insert="true"
access="property"
column="agency"
/>

<property
name="paperAdvertisementBudget"
type="int"
update="true"
insert="true"
access="property"
column="paperAdvertisementBudget"
/>

<many-to-one
name="user"
class="com.uniken.adsalesentities.UserImpl"
cascade="all"
outer-join="auto"
update="true"
insert="true"
access="property"
column="responsibleUserId"
/>

<many-to-one
name="accountCategory"
class="com.uniken.adsalesentities.AccountCategoryImpl"
cascade="all"
outer-join="auto"
update="true"
insert="true"
access="property"
column="accountCategoryName"
/>

<property
name="paymentTerms"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="paymentTerms"
/>

<property
name="creditLimits"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="creditLimits"
/>

</class>

</hibernate-mapping>


Please help me with the solution . It is very very urgent.
Hibernate team please look into this matter.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 5:48 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Are your UserImpl and/or AccountCategoryImpl objects used by more than one AccountImpl? It looks like they're supposed to be, but your mapping has been told to delete those objects when any object referring to them is deleted. So when you delete an AccountImpl, its AccountCategoryImpl is being deleted, but that's failing because other AccountImpls still refer to it.

Change your cascade level to something appropriate. Given that Users and Categories are conceptually permanent objects, they should probably be managed on their own, not via many-to-ones like you're donig. Change the cascade to "none", or at best "save-update".

P.S. Appropriate use of code tags makes mapping docs much more readable.

P.P.S. Why would the hibernate team look into a simple bug like this? That's what we plebians who actually make a profit from their hard work are for. They've already made their contribution to the open source community.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 5:51 am 
Newbie

Joined: Wed Feb 22, 2006 2:15 am
Posts: 10
Thank you.

It solved the problem.
Hibernate guys are really helpful.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.