|Re: EMF reference management [message #1240953 is a reply to message #1237390]
||Fri, 07 February 2014 09:08
| Ed Merks
Registered: July 2009
On 29/01/2014 5:09 PM, gwendal daniel wrote:
> I am working on an EMF project and I feel a bit confuse about EMF
> internal reference management.
> For example I have two classes Course and Topic. The Course contains
> several EReferences (changeable) to Topic and each Topic has a single
> EReference (non-changeable) to its Course.
> When I do some tests on that model, I found 2 strange behaviours:
> When I add a reference to a Topic into a Course instance the opposite
> reference is updated (even if it is non-changeable)
If it's an opposite it must get updated to remain consistent, but making
it non-changeable won't let you change it direct from that one side via
> When I use EcoreUtil.delete() on the Course object previously created,
> the object instance is correctly deleted but the reference into the
> Topic is not updated (it still refers to the Course that doesn't
> exists anymore)
I'm not sure from your description which references are containment
references and which aren't...
> I follow the exection of reference setters and EcoreUtil.delete() into
> the debugger and my first conclusion is that the first one doesn't
> care about changeable attribute whereas the second does.
> If someone can enlighten me on this point it would be helpful.
> [Edit] I got a part of the answer from the EMF IBM documentation :
>> Declaring one end of a bi-directional relationship to be not
>> changeable is a good way to force clients to always set the reference
>> from the other end, but still provide convenient navigation methods
>> from either end.
> But still doesn't understand why EcoreUtil.delete() doesn't remove the
> reference, even if it is not changeable.
Are there only two EReferences involved or more than two? I'm not sure
I understand the exact nature of the references involved. Did you use
org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject, boolean) with the
second argument set to true? If you delete a Course any contained
Topics will still be contained after the delete...
Professional Support: https://www.macromodeling.com/
Powered by FUDForum
. Page generated in 0.01962 seconds