-->
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: orphanRemoval not working properly
PostPosted: Mon Feb 09, 2015 5:25 am 
Newbie

Joined: Mon Feb 09, 2015 5:18 am
Posts: 1
Hi,

I have posted a question on StackOverflow (https://stackoverflow.com/posts/28370940), without success.
Can you please tell me if the folloing is a known bug ?

====

We have an issue that sound like a bug in Hibernate dealing with orphanRemoval=true for a oneToMany List (with index).

Here is the simplified mapping :
Code:
    public class ParentClass {
   
      [...]
   
      @OneToMany(cascade = ALL, mappedBy = "parent", orphanRemoval = true)
      @OnDelete(action = OnDeleteAction.CASCADE)
      @Fetch(FetchMode.JOIN)
      @OrderColumn(name = "pos", nullable = false)
      public List<ChildClass> getChildren() {
        return children;
      }
   
    }


And the child class :

Code:
    public class ChildClass {
        [...]

        @ManyToOne
        @JoinColumn(nullable = false, name = "parent_id")
        public ParentClass getParent() {
            return parent;
        }
    }


Given this mapping, the following scenario is failing :

1. Fetch a *Parent* from DB
2. Add a child to it
3. Get something else from DB (not same entity), producing a partial flush
4. Remove the child from the parent
5. Leave the transaction

Here is the code
Code:
    @Transactional
    public void test() {
       
      // 1)
      ParentClass parent = entityManager.find(ParentClass.class, "some-id");
           
      // 2)
      ChildClass child = new ChildClass(parent);
      parent.getChildren().add(child);
       
      // 3)
      entityManager.find(SomethingElse.class, "2");
       
      // 4)
      parent.getChildren().remove(child); 
    }


In that case, the child allocation is inserted into DB and not removed at te end of the transaction.

However, if we don't do step 3), the child allocation is correctly not persisted in DB

Is that a bug ? A wrong mapping ?
Is there a workaround for it ?


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.