Hi,

I've recently started using OrientDB, and so far I like it a lot.  Keep up 
the good work! Now as for the problem I'm having...

*Setup info:*
I'm running v1.7.4, and using an Object database.  

*Scenario:*
I have two classes: parent, child.  The parent has a reference to a child, 
and this reference is annotated with "@OneToOne(orphanRemoval = true)" .

The parent sets a reference to a newly created child, and is saved to the 
db. The reference is then changed to a different, newly created child 
object.  At this point, I expect the 1st child object which is now an 
orphan, to be removed when the parent is saved a 2nd time. This wasn't 
happening with the code that I was expecting to work.  After much wrestling 
with my code, finding some previous posts similar to this, and looking at 
your unit test code snippets, I found two other ways of coding the same 
thing that do actually work. I'll list here what works and what doesn't, 
but what I'm wondering is if this is expected behaviour or a bug.

*1. Code where orphan FAILS to get removed:*

            Parent parent = new Parent();
            
            Child child1 = new Child();
            child1.setDesc("Child 1");
            parent.setChild(child1);

            parent = db.save(parent);
            
            Child child2 = new Child();
            child2.setDesc("Child 2");
            parent.setChild(child2);
            
            parent = db.save(parent);

At this point both child1 and child2 still exist in the DB, however I was 
expecting child1 to be removed.

I've written similar code for deleting parents, and in those cases the 
child does get removed with a db.delete(parent), so I was expecting it to 
also work when doing a db.save(parent).


*2. Code where orphan SUCCESSFULLY gets removed:*


            Parent parent = new Parent();
            
            Child child1 = new Child();
            child1.setDesc("Child 1");
            *child1 = db.save(child1);*
            parent.setChild(child1);

            parent = db.save(parent);
            
            Child child2 = new Child();
            child2.setDesc("Child 2");
            *child2 = db.save(child2);*
            parent.setChild(child2);
            
            parent = db.save(parent);


*3. Another way of coding where orphan also SUCCESSFULLY gets removed:*

            Parent parent = new Parent();
            
            Child child1 = db.newInstance(Child.class);
            child1.setDesc("Child 1");
            parent.setChild(child1);

            parent = db.save(parent);
            
            Child child2 = db.newInstance(Child.class);
            child2.setDesc("Child 2");
            parent.setChild(child2);
            
            parent = db.save(parent);


To re-iterate my question, is it expected that code sample #1 above fails?  
It would be very convenient if it worked since the other 2 methods require 
the POJO setup part to have an instance of the database object.  This may 
not seem to matter in the simple code above, but in the project I'm working 
on, complex POJOs are created and modified in many places, but there is 
only a single class that has a database instance and handle synching them 
with the database and deals with thread-safe access to this instance (I 
used a database pool before, but ran into MVCC issues, but that is a 
separate matter :)).

Thanks,
Abes Dabir


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to