Community
Participate
Working Groups
Created attachment 200653 [details] JUnit test plugin, which tests the mentioned bug. I have the following situation: A car object is contained in one resource, a wheel object in another. The car has a containment reference for wheels. When the wheel is added to the car's wheels reference, the wheel should be removed from its containing resource, obviously. This works if I use generated code. It does not work with dynamic EObjects. The following JUnit plugin test case makes this more clear: ResourceSet rs = new ResourceSetImpl(); Resource r1 = rs.createResource(URI.createURI("r1")); Resource r2 = rs.createResource(URI.createURI("r2")); Resource mmr = rs.getResource( URI.createPlatformPluginURI("/emfTest/models/carExample.ecore", true), true); EPackage ePackage = (EPackage) mmr.getContents().get(0); EClass carEClass = (EClass) ePackage.getEClassifier("Car"); EClass wheelEClass = (EClass) ePackage.getEClassifier("Wheel"); /* * Create a car and add it to r1 */ EObject car = ePackage.getEFactoryInstance().create(carEClass); r1.getContents().add(car); /* * create a wheel and add it to r2 */ EObject wheel = ePackage.getEFactoryInstance().create(wheelEClass); r2.getContents().add(wheel); /* * Now, add the wheel to the car's wheels reference, which is a containment reference */ ((EList<EObject>) car.eGet(carEClass.getEStructuralFeature("wheels"))).add(wheel); /* * Now, the wheel should not be a root element of r2. * This assertions fails in case of dynamic EObjects. */ assertTrue(!r2.getContents().contains(wheel)); I have attached this code as a JUnit test plugin, which also includes the carExample.ecore file.
This is how proxy resolving containment references are supposed to work. If you want the behavior you're expecting, you'll need to set resolveProxies to false.