-->
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.  [ 5 posts ] 
Author Message
 Post subject: dynamic-delete
PostPosted: Thu Dec 21, 2006 8:46 am 
Newbie

Joined: Thu Dec 21, 2006 7:30 am
Posts: 11
If have some problem with deletion of subclasses.

The essence of my problem is.

two classes A and B. A is abstract

B extends A

it is mapped as

Code:
<class name="A" table="A">
   <id name="id" type="long" column="ID" />
   <joined-subclass name="B" table="B">
      <key column="ID"/>
   </joined-subclass>
</class>


if I call B.delete() the entry in table B is deleted while the entry in table A stays. Then when hibernate loads all entries of table A, I get an
Code:
InstantiationException: Cannot instantiate abstract class or interface: A
of course.

what I would like would be a tag like
Code:
dynamic-delete

however it does not exist.

So i tried:
Code:
<class name="A" table="A">
   <id name="id" type="long" column="ID" />
   <joined-subclass name="B" table="B">
      <key column="ID"/>
      <sql-delete>
         DELETE FROM B WHERE ID = ?; DELETE FROM A WHERE ID = ?
      </sql-delete>
   </joined-subclass>
</class>


But now i get an other kind of exception, namely:
Code:
Caused by: org.postgresql.util.PSQLException: No value specified for parameter 1.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 11:29 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I think you might just have to create your own delete method which deletes them both with that query in it.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 12:45 pm 
Newbie

Joined: Thu Dec 21, 2006 7:30 am
Posts: 11
found a solution -
thx anyway


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 6:20 pm 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
And, what is the solution? It's an important issue for my application.

Many thanks in advance.

Regards.

_________________
Please don't forget the credit system.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 3:04 am 
Newbie

Joined: Thu Dec 21, 2006 7:30 am
Posts: 11
First of all I use

dynamic-update="true"
dynamic-insert="true"

then I have made sure that references cascade on deletion.

My problem was actually a bit more complicated than I actually described in my simplified code example.

I have a more complex inheritance hierarchy, and the problem was when I deleted one of the subclasses, hibernate would try to delete it superclasses as well, but optimistically.
As another table had a refernce to one of these subclasses and the database was constrained correctly, the database forbid deleting of the superclass object.

Thus I got the InstantiationException.

Here is some of the actual mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2006-09-26 16:23:20 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
   <class name="entity.hibernate.Contactable" table='"Contactable"'
      schema='"public"' lazy="true" abstract="true">
      <id name="id" type="long">
         <column name='"ID"' />
         <generator class="sequence">
            <param name="sequence">"Contactable_ID_seq"</param>
         </generator>
      </id>
      <set name="contacts" table='"ContactList"' lazy="true">
         <key column='"ContactableID"' />
         <many-to-many class="entity.hibernate.Contact">
            <column name='"ContactID"' />
         </many-to-many>
      </set>
      <joined-subclass name="entity.hibernate.Trackable"
         table='"Trackable"' schema='"public"' lazy="true"
         dynamic-update="true" dynamic-insert="true" abstract="true">
         <key column='"ID"' />
         <set name="trackers" inverse="false" lazy="true">
            <key>
               <column name='"TrackableID"' />
            </key>
            <one-to-many class="entity.hibernate.Tracker" />
         </set>
         <joined-subclass name="entity.hibernate.Patient"
            table='"Patient"' schema='"public"' lazy="true"
            dynamic-update="true" dynamic-insert="true">
            <key column='"ID"' />
            <many-to-one name="statusProvider"
               class="entity.hibernate.StatusProvider" fetch="select"
               cascade="delete">
               <column name='"StatusProviderID"' />
            </many-to-one>
            <property name="name" type="string">
               <column name='"Name"' />
            </property>
            <property name="socialSecurityNumber" type="string">
               <column name='"SocialSecurityNumber"' />
            </property>
            <set name="surgeries" inverse="false" lazy="true">
               <key>
                  <column name='"PatientID"' />
               </key>
               <one-to-many class="entity.hibernate.Surgery" />
            </set>
         </joined-subclass>
         <joined-subclass name="entity.hibernate.Personnel"
            table='"Personnel"' schema='"public"' lazy="true"
            dynamic-update="true" dynamic-insert="true">
            <key column='"ID"' />
            <many-to-one name="personnelRole"
               class="entity.hibernate.PersonnelRole" fetch="select">
               <column name='"PersonnelRoleID"' not-null="true" />
            </many-to-one>
            <many-to-one name="statusProvider"
               class="entity.hibernate.StatusProvider" fetch="select"
               cascade="delete">
               <column name='"StatusProviderID"' />
            </many-to-one>
            <many-to-one name="securityContext"
               class="entity.hibernate.SecurityContext" fetch="select"
               not-null="true" cascade="delete">
               <column name='"SecurityContextID"' />
            </many-to-one>
            <property name="name" type="string">
               <column name='"Name"' />
            </property>
            <property name="userName" type="string">
               <column name='"UserName"' not-null="true" />
            </property>
            <property name="password" type="string">
               <column name='"Password"' not-null="true" />
            </property>
            <many-to-one name="image" class="entity.hibernate.Image"
               fetch="select">
               <column name='"ImageID"' />
            </many-to-one>
            <property name="abbreviatedName" type="string">
               <column name='"AbbreviatedName"' />
            </property>
            <property name="active" type="boolean">
               <column name='"Active"' not-null="true" />
            </property>
            <joined-subclass name="entity.hibernate.Substitute"
               table='"Substitute"' schema='"public"' lazy="true"
               dynamic-update="true" dynamic-insert="true">
               <key column='"ID"' />
               <property name="substitute" type="boolean">
                  <column name='"IsSubstitute"' not-null="true" />
               </property>
            </joined-subclass>
         </joined-subclass>
      </joined-subclass>
      <joined-subclass name="entity.hibernate.Location"
         table='"Location"' schema='"public"' lazy="true"
         dynamic-update="true" dynamic-insert="true">
         <key column='"ID"' />
         <property name="shortText" type="string">
            <column name='"ShortText"' />
         </property>
         <property name="longText" type="string">
            <column name='"LongText"' />
         </property>
         <set name="videoFeeds" inverse="false" lazy="true">
               <key>
                  <column name='"LocationID"' not-null="true" />
               </key>
               <one-to-many class="entity.hibernate.VideoFeed" />
            </set>
         <joined-subclass name="entity.hibernate.SurgeryRoom"
            table='"SurgeryRoom"' schema='"public"' lazy="true"
            dynamic-update="true" dynamic-insert="true">
            <key column='"ID"' />
            <property name="type" type="string">
               <column name='"Type"' />
            </property>
            <many-to-one name="ongoingSurgery"
               class="entity.hibernate.Surgery" fetch="select">
               <column name='"OngoingSurgeryID"' />
            </many-to-one>
            <property name="text" type="string">
               <column name='"Text"' />
            </property>
            <set name="teams" inverse="false" lazy="true">
               <key>
                  <column name='"SurgeryRoomID"' not-null="true" />
               </key>
               <one-to-many class="entity.hibernate.Team" />
            </set>
            <set name="surgeries" inverse="false" lazy="true">
               <key>
                  <column name='"SurgeryRoomID"' not-null="true" />
               </key>
               <one-to-many class="entity.hibernate.Surgery" />
            </set>
         </joined-subclass>
      </joined-subclass>
   </class>
</hibernate-mapping>


Inheritance is achived using "Table per subclass"


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