-->
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.  [ 3 posts ] 
Author Message
 Post subject: delete statements with union-subclasses that have primatives
PostPosted: Wed Oct 19, 2005 3:34 pm 
Newbie

Joined: Wed Dec 03, 2003 7:13 pm
Posts: 4
I'm having a problem using delete statements on models with union-subclass inheritance that have lists of primatives that are specified with cascade 'all-delete-orphan'.

Basically, deletes using the session.delete(model) work fine, but delete statements executed such as 'delete model' leave the list items orphaned.

I know delete statements for union-subclasses are new to 3.1 (and that's why we moved to it because we need this functionality!) - but perhaps they aren't implemented fully yet? If anyone has any suggestions or if you want me to submit a bug report let me know. Thanks!

Hibernate version:

3.1rc2 and 3.1rc1

Mapping document:

<code>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-cascade="save-update">
<class name="model.ModelImpl" table="MODEL" dynamic-insert="false" dynamic-update="false">
<id name="objectId" type="java.lang.String" unsaved-value="any">
<column name="OBJECT_ID" sql-type="VARCHAR(255) BINARY"/>
<generator class="assigned">
</generator>
</id>
<version name="objectVersion" type="int" column="objectVersion"/>
<union-subclass name="model.TestModelImpl" table="TEST_MODEL" dynamic-insert="false" dynamic-update="false" abstract="false">
<list name="testStringList" table="TEST_MODEL_testStringList" cascade="all-delete-orphan">
<key column="TEST_MODEL_testStringList"/>
<list-index column="TEST_STRING_LIST_IDX"/>
<element column="TEST_STRING_LIST" type="java.lang.String" not-null="false" unique="false" />
</list>
</union-subclass>
</class>
</hibernate-mapping>

</code>


Code between sessionFactory.openSession() and session.close():

The following is done on a model created with a list:

<code>

String query = "delete TestModelImpl";
Transaction transaction = session.beginTransaction();
Query hQuery = session.createQuery(query);
hQuery.executeUpdate();
transaction.commit();

</code>

Full stack trace of any exception that occurs:

No error is reported but the list items remain in the db. I then get an error when trying to re-insert a model with the same key (because list items already exist). Looking at the debug output, no call to delete list items is made.

Name and version of the database you are using:

MySql 5.

Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well, that is the ejb3 bulk query semantic; bulk deletes do *not* cascade to associations.

Hibernate will support this. There is a JIRA item to add support for specifying cascading of deletes in the delete statement:
http://opensource2.atlassian.com/projects/hibernate/browse/HHH-695


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 5:06 pm 
Newbie

Joined: Wed Dec 03, 2003 7:13 pm
Posts: 4
Thanks Steve for the very rapid response. I missed that, and found it odd moving from v2.

In addition to having to specify cascading deletes in the statement, it would be very nice to have a version that does respect cascade properties specified in the mapping files (closer to v2 functionality, as an option).

I suppose in the mean time I will create a convience method that does a select and then iterates over each result and deletes it individually, as suggested by the migration guide.


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