-->
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.  [ 6 posts ] 
Author Message
 Post subject: cascade delete on @OneToMany and @CollectionOfElements
PostPosted: Tue Sep 26, 2006 4:50 am 
Newbie

Joined: Thu Feb 12, 2004 7:53 pm
Posts: 2
Hibernate version: Hibernate 3.2cr4 , Hibernate Annotations 3.2cr2, Hsqldb 1.8.0.4

Assume the following code Node.java:
Code:
@Entity
@Table(name="node")
public class Node {
   private List<Node> children = new ArrayList<Node>();
   private Node parent;
   private Map<String, String> props = new HashMap<String, String>();
        ... only getters below,

   @OneToMany(mappedBy="parent", cascade={javax.persistence.CascadeType.ALL})
   @Cascade({CascadeType.ALL})
   @Fetch(FetchMode.SELECT)
   public List<Node> getChildren() {
      return children;
   }

   @ManyToOne
   public Node getParent() {
      return parent;
   }

   @CollectionOfElements
   @MapKey(columns={@Column(name="keyy", length=50)})  // keyy beacause key is reserved word in SQL
   @Column(name = "value", length = 2500)
   @Cascade({CascadeType.ALL})
    public Map<String, String> getProps() {
      return props;
   }

}

Node.java is intended to build a tree structure (parent, children). Each element of the tree might have an arbitrary list of key-value pairs (props). Inserting and updating works fine.

When trying to delete the whole Node tables using
Code:
session.createQuery("delete Node").executeUpdate()
an java.sql.SQLException: Integrity constraint violation FK881D06C3F51D9168 table: NODE in statement [delete from node]
The cause for this are the generated DDL statements:
Code:
create table node (id bigint generated by default as identity (start with 1), path varchar(255) not null, locale varchar(10), sort smallint not null, visible bit not null, parent_id bigint, primary key (id), unique (path))
create table node_props (node_id bigint not null, value varchar(2500), keyy varchar(50), primary key (node_id, keyy))
alter table node add constraint FK881D06C3F51D9168 foreign key (parent_id) references node
alter table node_props add constraint FK979BD4F4238E30AF foreign key (node_id) references avs_node

If the "alter table add contraint" would include "on delete cascade" it should work. I've specified the @Cascade annotation, so why is there no "on delete cascade" in DDL?
This behaviour occurs for both, the @OneToMany and the @CollectionOfElements annotation. Any hints?

Thanks in advance,
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:12 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the bulk operations are not aware of associations so far

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 25, 2007 5:38 am 
Newbie

Joined: Tue Jun 19, 2007 7:25 am
Posts: 7
So is there any chance to delete the collectionOfElements with HQL?
If the cascadeType is not supported I would like to do it manually, but as it is not an Entity I cannot name it in the query!
What would be the way to go in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 11:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't think it works either, this is the same kind of issues going on

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Cascade settings don't work with CollectionOfElements?
PostPosted: Tue Oct 02, 2007 5:44 pm 
Newbie

Joined: Fri Sep 14, 2007 2:02 pm
Posts: 10
Location: New York, NY
I found a similar problem during my migration from XDoclet to Annotations. An entity Coupons has a CollectionOfElements on Coupon objects, and Coupon objects have a many to one reference to Payout:

Code:
@Entity
@Table(name="COUPONS")
public class Coupons {
...
@Embedded
private CouponSchedule
...
}

@Embeddable
public class CouponSchedule {
...
@CollectionOfElements(fetch=FetchType.EAGER)
@Cascade(CascadeType.ALL)
@JoinTable(name="COUPON_SCHEDULE", joinColumns=@JoinColumn(name="COUPONS_ID"))
@IndexColumn(name="COUPON_POS")
private List<Coupon> coupons;
...
}

@Embeddable
public class Coupon {
...
@ManyToOne(cascade=CascadeType.All, fetch=FetchType.EAGER)
@JoinColumn(name="PAYOUT")
private Payout payout;
...
}

@Entity
@Table(name="PAYOUT")
public class Payout {
...
}


When I try to save a coupons object, I get an error because the Payout object is not saved. Payout should've been saved though, and having stepped through the Hibernate code it looks like the cascadeType is incorrectly set to NONE on everything below Coupons. Is CollectionOfElements just ignoring Cascade attributes?


Top
 Profile  
 
 Post subject: Re: cascade delete on @OneToMany and @CollectionOfElements
PostPosted: Wed Feb 17, 2010 9:36 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Any news on this issue?

_________________
http://nocxsville.myminicity.com/


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