-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transitive (deep) cascade deletion
PostPosted: Fri Sep 21, 2012 8:07 am 
Newbie

Joined: Fri Sep 21, 2012 7:02 am
Posts: 2
Here is situation:

A incl B incl C

Code:
class A
{
    private Long id_a;
    private String name;
    private Set<B> bSet;
   
    //def. consturctor
    //getters&setters
}


Code:
A.hbm.xml

<hibernate-mapping>
    <class name="A" table="a">
        <id column="id_a"
            name="ID_A"
            type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">A_seq</param>
            </generator>
        </id>

        <property name="name"
                  column="NAME"
                  type="java.lang.String"
                  length="256"/>

        <set name="bSet"
             table="b"
             lazy="true"
             cascade="delete">
            <key column="id_a"
                 not-null="true">
            </key>
            <one-to-many class="B" />
        </set>
    </class>
</hibernate-mapping>


Code:
class B
{
    private Long id_b;
    private Long id_a;
    private String name;
    private Set<C> cSet;
   
    //def. consturctor
    //getters&setters
}


Code:
B.hbm.xml

<hibernate-mapping>
    <class name="B" table="b">
        <id column="id_b"
            name="ID_B"
            type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">B_seq</param>
            </generator>
        </id>

        <property name="id_a"
                  column="ID_A"
                  type="java.lang.String"
                  length="256"
                  insert="false"
                  update="false"/>

        <property name="name"
                  column="NAME"
                  type="java.lang.String"
                  length="256"/>

        <set name="cSet"
             table="c"
             lazy="true"
             cascade="delete">
            <key column="id_b"
                 not-null="true">
            </key>
            <one-to-many class="C" />
        </set>
    </class>
</hibernate-mapping>


Code:
class C
{
    private Long id_c;
    private Long id_b;
    private Clob data;
   
    //def. consturctor
    //getters&setters
}


Code:
C.hbm.xml

<hibernate-mapping>
    <class name="C" table="c">
        <id column="id_c"
            name="ID_C"
            type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">C_seq</param>
            </generator>
        </id>

        <property name="id_b"
                  column="ID_B"
                  type="java.lang.String"
                  length="256"
                  insert="false"
                  update="false"/>

        <property name="data"
                  column="DATA"
                  type="java.lang.Clob"
                  length="256"/>

    </class>
</hibernate-mapping>


client

Code:
//(the row with id_a=1 is already exist)
String stmt = "from A as t where t.id_a=1";
Query query = session.createQuery(stmt);
A a = (A) query.list().get(0);
session.delete(a);


Output
*******************************************************************
>>> org.hibernate.exception.SQLGrammarException: could not initialize a collection: [B.cSet#1]<<<
--> [(1) org.hibernate.exception.SQLStateConverter.convert at: SQLStateConverter.java:92
--> [(2) org.hibernate.exception.JDBCExceptionHelper.convert at: JDBCExceptionHelper.java:66
--> [(3) org.hibernate.loader.Loader.loadCollection at: Loader.java:2173
--> [(4) org.hibernate.loader.collection.CollectionLoader.initialize at: CollectionLoader.java:62
--> [(5) org.hibernate.persister.collection.AbstractCollectionPersister.initialize at: AbstractCollectionPersister.java:627
--> [(6) org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection at: DefaultInitializeCollectionEventListener.java:83
--> [(7) org.hibernate.impl.SessionImpl.initializeCollection at: SessionImpl.java:1863
--> [(8) org.hibernate.collection.AbstractPersistentCollection.initialize at: AbstractPersistentCollection.java:369
--> [(9) org.hibernate.collection.AbstractPersistentCollection.read at: AbstractPersistentCollection.java:111
--> [(10) org.hibernate.collection.PersistentSet.iterator at: PersistentSet.java:186
**********************************************************************

How can I delete ALL references? Not only explicit (from B set) but transitive (from C set) also.
As well as it mustn't be missing the capability to delete B instance with cascade deletion from C.
Hibernate v3.0


Last edited by __Denis on Tue Sep 25, 2012 6:23 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Transitive (deep) cascade deletion
PostPosted: Tue Sep 25, 2012 6:15 am 
Newbie

Joined: Fri Sep 21, 2012 7:02 am
Posts: 2
Sorry. Transitive cascade deletion is executed properly (with some reservation). When you try to delete the objects containing the set of the objects which containing CLOB or BLOB data members it is thrown: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [B.cSet#1]. If you try to execute the select of the foregoing objects you'll get:unable to evaluate the expression Method threw 'org.hibernate.exception.SQLGrammarException' exception.


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