Hibernate version:2.1.6
Mapping documents:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping auto-import="true"> <!-- Article --> <class name="com.calltoislam.model.Article" table="T_ARTICLE" > <id name="id" type="int" column="ARTICLE_ID" unsaved-value="-1"> <generator class="identity"/> </id> <property name="title" column="TITLE" /> <property name="description" column="DESCRIPTION" /> <property name="publishedDate" column="PUBLISHED_DATE" /> <property name="text" column="TEXT" /> <property name="type" column="TYPE" /> <property name="path" column="PATH" /> <many-to-one name="author" class="com.calltoislam.model.Author" column="SCHOLAR_ID" cascade="none"/> <many-to-one name="category" class="com.calltoislam.model.Category" column="CATEGORY_ID"/> </class> <!-- Category --> <class name="com.calltoislam.model.Category" table="T_CATEGORY" > <id name="id" type="int" column="CATEGORY_ID" unsaved-value="-1"> <generator class="identity"/> </id> <property name="name" column="NAME" /> <property name="description" column="DESCRIPTION" /> <bag name="articles" cascade="all-delete-orphan" inverse="true"> <key column="CATEGORY_ID"/> <one-to-many class="com.calltoislam.model.Article"/> </bag> <bag name="audios" cascade="all-delete-orphan" inverse="true"> <key column="CATEGORY_ID"/> <one-to-many class="com.calltoislam.model.Audio"/> </bag> <bag name="videos" cascade="all-delete-orphan" inverse="true"> <key column="CATEGORY_ID"/> <one-to-many class="com.calltoislam.model.Video"/> </bag> </class> <!-- Scholar --> <class name="com.calltoislam.model.Scholar" table="T_SCHOLAR"> <id name="id" type="int" column="SCHOLAR_ID" unsaved-value="-1"> <generator class="identity"/> </id> <discriminator column="TYPE" type="string"/> <property name="name" column="NAME"/> <property name="biodata" column="BIODATA"/> <!-- Author --> <subclass name="com.calltoislam.model.Author" discriminator-value="A"> <bag name="articles" inverse="true" cascade="all-delete-orphan"> <key column="SCHOLAR_ID"/> <one-to-many class="com.calltoislam.model.Article"/> </bag> </subclass> <!-- Lecturer --> <subclass name="com.calltoislam.model.Lecturer" discriminator-value="L"> <bag name="audios" inverse="true" cascade="all-delete-orphan"> <key column="SCHOLAR_ID"/> <one-to-many class="com.calltoislam.model.Audio"/> </bag> </subclass> <!-- Presenter --> <subclass name="com.calltoislam.model.Presenter" discriminator-value="P"> <bag name="videos" inverse="true" cascade="all-delete-orphan"> <key column="SCHOLAR_ID"/> <one-to-many class="com.calltoislam.model.Video"/> </bag> </subclass> </class> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Category cat = (Category)session.find("from " + Category.class.getName() + " where id = 1").iterator().next();session.delete(cat);
Full stack trace of any exception that occurs:net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 6, of class: com.calltoislam.model.Article at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:752) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:730) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1376) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482) at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2673) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2250) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.calltoislam.AbstractCallToIslamTest.tearDown(AbstractCallToIslamTest.java:61) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Name and version of the database you are using:MySql
The generated SQL (show_sql=true):Hibernate: select category0_.CATEGORY_ID as CATEGORY1_, category0_.NAME as NAME, category0_.DESCRIPTION as DESCRIPT3_ from T_CATEGORY category0_ where (category0_.CATEGORY_ID=? ) Hibernate: select videos0_.CATEGORY_ID as CATEGORY8___, videos0_.MULTIMEDIA_ID as MULTIMED1___, videos0_.MULTIMEDIA_ID as MULTIMED1_1_, videos0_.SCHOLAR_ID as SCHOLAR_ID1_, videos0_.CATEGORY_ID as CATEGORY8_1_, videos0_.TITLE as TITLE1_, videos0_.DESCRIPTION as DESCRIPT4_1_, videos0_.PUBLISHED_DATE as PUBLISHE5_1_, videos0_.PATH as PATH1_, presenter1_.SCHOLAR_ID as SCHOLAR_ID0_, presenter1_.NAME as NAME0_, presenter1_.BIODATA as BIODATA0_ from T_MULTIMEDIA videos0_ left outer join T_SCHOLAR presenter1_ on videos0_.SCHOLAR_ID=presenter1_.SCHOLAR_ID where videos0_.CATEGORY_ID=? Hibernate: select audios0_.CATEGORY_ID as CATEGORY8___, audios0_.MULTIMEDIA_ID as MULTIMED1___, audios0_.MULTIMEDIA_ID as MULTIMED1_1_, audios0_.SCHOLAR_ID as SCHOLAR_ID1_, audios0_.CATEGORY_ID as CATEGORY8_1_, audios0_.TITLE as TITLE1_, audios0_.DESCRIPTION as DESCRIPT4_1_, audios0_.PUBLISHED_DATE as PUBLISHE5_1_, audios0_.PATH as PATH1_, lecturer1_.SCHOLAR_ID as SCHOLAR_ID0_, lecturer1_.NAME as NAME0_, lecturer1_.BIODATA as BIODATA0_ from T_MULTIMEDIA audios0_ left outer join T_SCHOLAR lecturer1_ on audios0_.SCHOLAR_ID=lecturer1_.SCHOLAR_ID where audios0_.CATEGORY_ID=? Hibernate: select articles0_.CATEGORY_ID as CATEGORY9___, articles0_.ARTICLE_ID as ARTICLE_ID__, articles0_.ARTICLE_ID as ARTICLE_ID1_, articles0_.TITLE as TITLE1_, articles0_.DESCRIPTION as DESCRIPT3_1_, articles0_.PUBLISHED_DATE as PUBLISHE4_1_, articles0_.TEXT as TEXT1_, articles0_.TYPE as TYPE1_, articles0_.PATH as PATH1_, articles0_.SCHOLAR_ID as SCHOLAR_ID1_, articles0_.CATEGORY_ID as CATEGORY9_1_, author1_.SCHOLAR_ID as SCHOLAR_ID0_, author1_.NAME as NAME0_, author1_.BIODATA as BIODATA0_ from T_ARTICLE articles0_ left outer join T_SCHOLAR author1_ on articles0_.SCHOLAR_ID=author1_.SCHOLAR_ID where articles0_.CATEGORY_ID=? Hibernate: select articles0_.SCHOLAR_ID as SCHOLAR_ID__, articles0_.ARTICLE_ID as ARTICLE_ID__, articles0_.ARTICLE_ID as ARTICLE_ID1_, articles0_.TITLE as TITLE1_, articles0_.DESCRIPTION as DESCRIPT3_1_, articles0_.PUBLISHED_DATE as PUBLISHE4_1_, articles0_.TEXT as TEXT1_, articles0_.TYPE as TYPE1_, articles0_.PATH as PATH1_, articles0_.SCHOLAR_ID as SCHOLAR_ID1_, articles0_.CATEGORY_ID as CATEGORY9_1_, category1_.CATEGORY_ID as CATEGORY1_0_, category1_.NAME as NAME0_, category1_.DESCRIPTION as DESCRIPT3_0_ from T_ARTICLE articles0_ left outer join T_CATEGORY category1_ on articles0_.CATEGORY_ID=category1_.CATEGORY_ID where articles0_.SCHOLAR_ID=?
Debug level Hibernate log excerpt:
|