-->
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.  [ 11 posts ] 
Author Message
 Post subject: constraint exception - lazy collections & delete
PostPosted: Tue Jan 27, 2004 7:28 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
I am getting a constraint exception (Sql error) on delete. Here are the mapping files:

Code:
<hibernate-mapping>
    <class name="com.gsk.les.bo.himpl.IHLog" table="LOG">
       <id name="id" type="long" column="id">
           <generator class="native"/>
        </id>
        
        <property name="key" column="KEY_VAL" type="string"/>
        
        <bag name="logEntries" table="LOG_LOG_ENTRIES_LIST"
              cascade="all" inverse="false" lazy="true">
           <key column="LOG_ID"/>
           <many-to-many column="LOG_ENTRY_ID" class="com.gsk.les.bo.himpl.IHLogEntry"/>
        </bag>
    </class>
</hibernate-mapping>


<hibernate-mapping>
    <class name="com.gsk.les.bo.himpl.IHLogEntry" table="LOG_ENTRIES">
       <id name="id" type="long" column="id">
           <generator class="native"/>
        </id>
       
        <property name="dateTime" column="DATE_TIME" not-null="true" type="calendar"/>
       
       <joined-subclass name="com.gsk.les.bo.himpl.IHLogEntrySmall"
                table="LOG_ENTRY_SMALL">
          <key column="LOG_ENTRY_ID"/>
          <property name="message" column="MESSAGE" type="string"/>
       </joined-subclass>
       <joined-subclass name="com.gsk.les.bo.himpl.IHLogEntryLarge"
                   table="LOG_ENTRY_LARGE">
          <key column="LOG_ENTRY_ID"/>
          <property name="clob" column="CLOB_VAL" type="clob"/>
       </joined-subclass>
    </class>
</hibernate-mapping>


Here is the scenario... I just changed this code to lazy initialize. Previously, I could do deletes and not get this error. After making it a lazy collection, I get this error.

Here is the code that does the delete...

Code:
Log cLog = getSearchRequest().getLog(LogKeys.COPY_LOG);
      if(cLog != null) {
         getSearchRequest().removeLog(cLog);
         getBPS().updateSearchRequest(getSearchRequest());
         getBPS().deleteLog(cLog);
      }


The error I get is....

ORA-02292 integrity constraint... violated - child record found.

What am I doing wrong


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 8:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please be more detailed in your code listing. It's really impossible to figure out what you are doing with the code you posted.


Top
 Profile  
 
 Post subject: What do you need...
PostPosted: Tue Jan 27, 2004 8:23 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
Basically in my code segement, I am cleaning up a set of logs that got created. The searchRequest contains the logs (in a map) per below:

Code:
<hibernate-mapping>
    <class name="com.gsk.les.bo.himpl.IHSearchRequest" table="SEARCH_REQUEST">
        <id name="id" type="long" column="id">
           <generator class="native"/>
        </id>
        
        <property name="dateOfCreation" column="DATE_OF_CREATION" type="calendar"/>
        <property name="name" column="NAME" type="string"/>
        <property name="state" column="STATE" type="string"/>
        <property name="readyToProcess" column="READY2PROCESS" type="boolean"/>
       
        <many-to-one name="legalCollection" column="LEGAL_COLL_ID"
                 cascade="none" class="com.gsk.les.bo.himpl.IHLegalCollection"/>
        <many-to-one name="resultsGroup" column="RESULT_GRP_ID"
                 cascade="none" class="com.gsk.les.bo.himpl.IHResultsGroup"/>
       
        <map name="contentTypeMgrs" table="CNTN_TYPE_MGRS_MAP"
                 cascade="all">
           <key column="SEARCH_REQ_ID"/>
           <index column="MAP_KEY" type="string"/>
           <many-to-many column="CNTN_TYPE_MGR_ID" class="com.gsk.les.bo.himpl.IHContentTypeMgr"/>
        </map>

        <map name="logs" table="SEARCH_REQ_LOGS_MAP"
              cascade="all">
           <key column="SEARCH_REQ_ID"/>
           <index column="MAP_KEY" type="string"/>
           <many-to-many column="LOG_ID" class="com.gsk.les.bo.himpl.IHLog"/>
        </map>

        <set name="queryTerms" table="SRCH_REQ_QUERY_TERMS_SET"
              cascade="none">
           <key column="SEARCH_REQ_ID"/>
           <many-to-many column="QUERY_TERM_ID" class="com.gsk.les.bo.himpl.IHQueryTerm"/>
        </set>
    </class>
</hibernate-mapping>


the getBPS().updateSearchCollection(sr) call is a call that performs and single transaction based saveOrUpdate() on the search request in question. Simarly deleteLog() performs an single transaction delete() on the log in question. Note for both of these there is a session.reconnect/session.disconnect enclosure.


Top
 Profile  
 
 Post subject: Oh and note
PostPosted: Tue Jan 27, 2004 10:37 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
Oh one thing to note... the exception indicates that:

a. the LogEntry was a LogEntryLarge (subtype).
b. and that the exception indicates that it could not delete the LogEntryLarge db row because it violated the constraint given to it with LogEntry (superclass).


Top
 Profile  
 
 Post subject: Found two things...
PostPosted: Wed Jan 28, 2004 8:59 am 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
Found two things with further testing...

1. It seems you can't just delete an entity that holds a lazy collection until the collection is initialized??

2. That list.clear() does not cascade its deletes to the collection entities and/or a entity held in a collection that uses/has a joined-subclass will produce a constraint violation...

Any clues?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2004 10:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
It seems you can't just delete an entity that holds a lazy collection until the collection is initialized??


This is not correct. The delete algorithm automatically loads any lazy collections owned by the deleted object at flush time.


Quote:
That list.clear() does not cascade its deletes to the collection entities and/or a entity held in a collection


As is very clearly stated in the Hibernate documentation, removing an entity from a collection does *not* cause it to be deleted unless you use cascade="all-delete-orphan".


Top
 Profile  
 
 Post subject: Okay, but that is confusing...
PostPosted: Wed Jan 28, 2004 12:22 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
Gavin,

Below is Section 13.4 of the doc...

Quote:
Occasionally, deleting collection elements one by one can be extremely inefficient. Hibernate isn't completly stupid, so it knows not to do that in the case of an newly-empty collection (if you called list.clear(), for example). In this case, Hibernate will issue a single DELETE and we are done!


That statement (with the title of "One Shot Delete") led me to conclusion that this was the way to perform an efficient delete of large collections. My apologies.

So a couple of follow-up questions:

1. What is the best way to perform a delete of a very large (both in numbers and in size of the things) collection, without "initializing" it. At the point in time that I want to delete this, I want to delete all things and I really don't care (in fact I don't want the burden of bringing them into scope) about the collection being initialized.

2. Does deletion work for a joined-subclass contain entity? I am getting a constraint violation every time I delete the collection holding an entity that has joined subclass


Top
 Profile  
 
 Post subject: And btw...
PostPosted: Wed Jan 28, 2004 12:23 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
Meant to add... You guys have done some good work on Hibernate! Kudos!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
What is the best way to perform a delete of a very large collection, without "initializing" it.


This is not possible, HIbernate has higher-level semantics (cascade, collection, lifecycle) that must be preserved and can only be done by initializing the collection.

Quote:
does deletion work for a joined-subclass contain entity?


of course.


Top
 Profile  
 
 Post subject: so should i can i??
PostPosted: Wed Jan 28, 2004 3:56 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 11:22 am
Posts: 20
So should I just collection.clear() and then perform a bulk SQL delete? To avoid the initialization?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2004 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
sure, you can write direct SQL for this, that makes sense.


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