-->
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: JPA - delete statement via Query and Cascade
PostPosted: Fri Feb 12, 2010 4:47 pm 
Newbie

Joined: Sat Oct 17, 2009 9:50 am
Posts: 4
Hi all

I tried to use a delete statement via a query. Obviously it seems that the "Cascade" gets not recognized. It deletes only the parent object but not the child objects. Any Ideas why? Is this not supported or did I something wrong?
When I do the same thing via the entityManager it works fine e.g. entityManager.remove(parent);
Thanky oyu for any hints.

Example JPA mapping:

class Parent {
@OneToMany (cascade=CascadeType.ALL)
@JoinColumn(name = "parent_id", nullable = false)
private List<Child> childs= new ArrayList<Child>();
}

In my DAO:

StringBuffer sb = new StringBuffer("delete from Parent p");
Query query = entityManager.createQuery (sb.toString());
query.executeUpdate();

During execution it shows only one SQL statement:

Hibernate: delete from parent


Top
 Profile  
 
 Post subject: Re: JPA - delete statement via Query and Cascade
PostPosted: Fri Feb 12, 2010 5:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Considering the JPA spec *explicity* states that cascades should not be taken into account in JPAQL delete statements...


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.