L
Larry Yondespor
I use Hibernate and I am not able to do cascade delete.
After I create a project I have:
select * from project;
uid | name | shortdescription
-----+------+-----------------
1 | nc | NC Web application
(1 row)
After I subscribe to the project I have:
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | 1 | 1
(1 row)
When I delete the project with a simple session.delete
try {
session.delete(project);
session.flush();
} catch (HibernateException e) {...
the row is deleted in the table "project"
but the row stays in table "subscription". Only the column entry "project" is set to null.
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | | 1
(1 row)
I want the row to be deleted, how do I do that?
My two tables one for Projects and one for Subscriptions
<hibernate-mapping>
<class name="org.cobra.persistence.Project" table="project">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name">
<column name="name" sql-type="char(32)" not-null="true"/>
</property>
<property name="shortDescription">
<column name="shortDescription" sql-type="char(256)" not-null="true"/>
</property>
<set name="subscriptions" table="subscription" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.Subscription"/>
</set>
<set name="subscriptionsRequested" table="subscriptionRequest" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.SubscriptionRequest"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.cobra.persistence.Subscription" table="subscription">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<many-to-one name="account" column="account" cascade="all" class="org.cobra.persistence.Account" />
<many-to-one name="project" column="project" cascade="all" class="org.cobra.persistence.Project" />
<many-to-one name="role" column="role" cascade="all" class="org.cobra.persistence.Role" />
</class>
</hibernate-mapping>
After I create a project I have:
select * from project;
uid | name | shortdescription
-----+------+-----------------
1 | nc | NC Web application
(1 row)
After I subscribe to the project I have:
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | 1 | 1
(1 row)
When I delete the project with a simple session.delete
try {
session.delete(project);
session.flush();
} catch (HibernateException e) {...
the row is deleted in the table "project"
but the row stays in table "subscription". Only the column entry "project" is set to null.
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | | 1
(1 row)
I want the row to be deleted, how do I do that?
My two tables one for Projects and one for Subscriptions
<hibernate-mapping>
<class name="org.cobra.persistence.Project" table="project">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name">
<column name="name" sql-type="char(32)" not-null="true"/>
</property>
<property name="shortDescription">
<column name="shortDescription" sql-type="char(256)" not-null="true"/>
</property>
<set name="subscriptions" table="subscription" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.Subscription"/>
</set>
<set name="subscriptionsRequested" table="subscriptionRequest" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.SubscriptionRequest"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.cobra.persistence.Subscription" table="subscription">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<many-to-one name="account" column="account" cascade="all" class="org.cobra.persistence.Account" />
<many-to-one name="project" column="project" cascade="all" class="org.cobra.persistence.Project" />
<many-to-one name="role" column="role" cascade="all" class="org.cobra.persistence.Role" />
</class>
</hibernate-mapping>