-->
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.  [ 1 post ] 
Author Message
 Post subject: One shot delete on onetomany association
PostPosted: Tue Oct 26, 2010 6:24 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2010 6:12 pm
Posts: 29
I have been trying to get one-shot delete working on my one-to-many association using only collection semantics but with no luck. Would be great if some one can provide pointers on this.

Code:
// The entities
class Users{
...
    public void setPhones(Set<Phone> phones){
        this.phones = phones;
    }

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="users", orphanRemoval=true)
    public Set<Phone> getPhones(){
        return this.phones;
    }
...
}
class Phone{
...
       @ManyToOne()
       @JoinColumn(name="USER_ID")
       public Users getUsers() {
           return users;
       }

       public void setUsers(Users users) {
           this.users = users;
       }
...
}
//The application code...
Users u = (Users)s.get(Users.class, new Integer(220));
u.getPhones().clear();


The above results in multiple delete statements to delete the phone entries. I'd rather prefer a single delete statement for the obvious advantage. I am able to perform this in one shot using queries (native or HQL) but I would prefer doing using collection methods due to the number of places I'd have to make this change.

The manual mentions that one-shot delete can be forced "at any time by discarding (i.e. dereferencing) the original collection and returning a newly instantiated collection with all the current elements.". What does this mean? Replacing the collection with a newly instantiated collection results in an exception about orphan-removal.

The manual also mentions that "One-shot-delete does not apply to collections mapped inverse=true.". Why is that the case? Using version 3.5

Thanks for your inputs.

PS: Have asked this question elsewhere, but figure folks here might be able to provide some ideas.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.