-->
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.  [ 9 posts ] 
Author Message
 Post subject: Cascade="all" ignored with composite element
PostPosted: Tue Apr 01, 2008 8:04 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
Hello everybody!

I have a n:m relation between two objects with a composite element in between.
When i want to delete the object I get an Exception saying that there are still childentities.
Adding cascade="all" doesn't solve this issue. Can someone see y ??
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="PersistenceLayer.Entity, PersistenceLayer" table="entities">
    <id name="Id" column="typeId" type="String">
      <generator class="uuid.hex" />
    </id>
    <property name="Name" column="name" type="string" />
    <property name="Description" column="description" type="string" />

    <idbag name="ChildEntities" table="entities_attributes" cascade="all">
      <collection-id type="String" column="types_attributes_id">
        <generator class="uuid.hex" />
      </collection-id>
      <key column="entityId" />
      <composite-element class="PersistenceLayer.CompositeElements.EntityAttribute, PersistenceLayer">
        <property name="Value" column="value" />
        <many-to-one name="Attribute" column="attributeId" class="PersistenceLayer.Attribute, PersistenceLayer" lazy="false" />
      </composite-element>
    </idbag>

    <bag name="Changes" cascade="all">
      <key column="typeId" />
      <one-to-many class="PersistenceLayer.History, PersistenceLayer" />
    </bag>
  </class>
</hibernate-mapping>


Exception:
Code:
Test method TypeServiceTest.CopyTypeTest threw exception:  Spring.Data.UncategorizedAdoException: Hibernate operation: could not delete: [PersistenceLayer.Entity#b120088015fc4881991172f7a2fbbe72][SQL: DELETE FROM entities WHERE entityId = ?]; uncategorized DataException for SQL [DELETE FROM entities WHERE entityId = ?]; ErrorCode [<no error code>]; ORA-02292: Verstoß gegen Constraint (DB.FKB029AD7E7D46EB33). Untergeordneter Datensatz gefunden.
--->  System.Data.OracleClient.OracleException: ORA-02292: Verstoß gegen Constraint (DB.FKB029AD7E7D46EB33). Untergeordneter Datensatz gefunden.
.


Top
 Profile  
 
 Post subject: Cascade="all" ignored with composite element
PostPosted: Tue Apr 01, 2008 8:44 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Mark,

I think you need the "all-delete-orphan" option to have child collections deleted automaticaly.

http://www.hibernate.org/hib_docs/reference/en/html/example-parentchild.html

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 9:07 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
hi ff,

i already tried different options, but the cascade attribute seems to be totally ignored.
I also tried it with different collection types (set etc.), but all of them are ignored with this composite element.

It is not ignored when I use it with collections that have no composite element.


Top
 Profile  
 
 Post subject: Cascade="all" ignored with composite element
PostPosted: Tue Apr 01, 2008 10:31 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi marks,

Can you try inverse="false" on the bag too?

Regards,
Richard


Top
 Profile  
 
 Post subject: Re: Cascade="all" ignored with composite element
PostPosted: Tue Apr 01, 2008 10:52 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
FlukeFan wrote:
Hi marks,

Can you try inverse="false" on the bag too?

Regards,
Richard


same behaviour :-/


Top
 Profile  
 
 Post subject: Cascade="all" ignored with composite element
PostPosted: Tue Apr 01, 2008 11:16 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi marks,

I think that should work ok - I tried a cut-down version of the mapping on a small test database.

Just to confirm what you're expecting:

If you delete an Entity with id 1 (say), you should get:
delete from entities_attributes where entityId = 1;
delete from entities where typeId=1;

No Attribute classes will be deleted (unless you specify cascase="all" on the many-to-one too).

Regards,
Richard


Top
 Profile  
 
 Post subject: Re: Cascade="all" ignored with composite element
PostPosted: Wed Apr 02, 2008 3:06 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
FlukeFan wrote:
Hi marks,

I think that should work ok - I tried a cut-down version of the mapping on a small test database.

Just to confirm what you're expecting:

If you delete an Entity with id 1 (say), you should get:
delete from entities_attributes where entityId = 1;
delete from entities where typeId=1;

No Attribute classes will be deleted (unless you specify cascase="all" on the many-to-one too).

Regards,
Richard


exactly. I don't want to delete the attributes, just the entries in the entries_attributs table.

You say that these mapping files work fine?

I'll come up with a simple demo application that demonstrates the odd behaviour, Unfortunately I've little time, but I'll try to


Top
 Profile  
 
 Post subject: Cascade="all" ignored with composite element
PostPosted: Wed Apr 02, 2008 4:16 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi marks,

Here's a link to the example I was using (extract to a folder, run the commandprompt.bat, and type 'nant'):
http://www.uploading.com/files/GH8K1B0L/SimpleNHibernateExampleM2NComposite.zip.html

Here's the mapping file I used ... maybe you can spot a difference:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

    <class  name="Nhd.Poco1, Runner"
            table="Poco1">

        <id name="Id" column="Poco1_Id">
            <generator class="native"/>
        </id>

        <property       name="Name"             column="Name"/>

        <idbag name="Children" table="poco1_join_poco2" cascade="all">
          <collection-id type="String" column="join_id">
            <generator class="uuid.hex" />
          </collection-id>
          <key column="Poco1_id" />
          <composite-element class="Nhd.Poco1Join, Runner">
            <many-to-one name="Poco2" column="Poco2_id" class="Nhd.Poco2, Runner" lazy="false"/>
          </composite-element>
        </idbag>
    </class>

</hibernate-mapping>


Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 4:21 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
Hi Richard!

Thx very much, I'll give it a try later this day, as soon as I have time :)

I'm already excited whats different to mine,

regards!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.