-->
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.  [ 1 post ] 
Author Message
 Post subject: Parent entity survives without child incase of exception!
PostPosted: Thu Apr 03, 2008 10:02 am 
Newbie

Joined: Thu Apr 03, 2008 9:33 am
Posts: 2
Hibernate version: 3.2.6

Mapping documents:
The mapping is logical relation for Country - State; User entity is mapped to the country...

in country.hbm.xml i have this mapping
<set name="states" table="state" order-by="lower(name) asc" cascade="all,delete-orphan" inverse="true">
<key column="country"/>
<one-to-many class="State"/>
</set>

in state.hbm.xml i have this mapping
<many-to-one name="country" class="Country" column="country" not-null="true" />

in user.hbm.xml i have this mapping
<many-to-one name="country" class="Country" column="country">

Full stack trace of any exception that occurs:
Hibernate: delete from state where id=?
Hibernate: delete from country where id=?
2008-04-03 18:50:09,994 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1451, SQLState: 23000
2008-04-03 18:50:09,994 ERROR [org.hibernate.util.JDBCExceptionReporter] - Duplicate key or integrity constraint violation message from server: "Cannot delete or update a parent row: a foreign key constraint fails (`user`, CONSTRAINT `FK36EBCBF1C33126` FOREIGN KEY (`country`) REFERENCES `country` (`id`))"
2008-04-03 18:50:10,025 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - 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:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:375)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:797)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:793)
at com.as.bpl.FMSBplImpl.deleteEntity(BplImpl.java:25)
at com.as.web.controller.MySimpleFormController.handleRequest(MySimpleFormController.java:48)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:453)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot delete or update a parent row: a foreign key constraint fails (`user`, CONSTRAINT `FK36EBCBF1C33126` FOREIGN KEY (`country`) REFERENCES `country` (`id`))"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 30 more

Name and version of the database you are using:MySQL 5

I have the mapping like as mentioned above...
Now when i delete a country X, first the states of the country X gets deleted, then as an user is mapped to the same country X, the country doesn't get deleted due to the exception...

how should i configure to get the transaction either be complete/nothing...

also im using the org.springframework.orm.hibernate3.HibernateTransactionManager, do i have to do something with my TM??

Thanks


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

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.