Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF reference management
EMF reference management [message #1237390] Wed, 29 January 2014 15:37 Go to next message
gwendal daniel is currently offline gwendal danielFriend
Messages: 7
Registered: January 2014
Junior Member
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)
  • 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 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.

Thanks

[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.
Re: EMF reference management [message #1240953 is a reply to message #1237390] Fri, 07 February 2014 09:08 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Comments below.

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
the APIs.
> 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.
>
> Thanks
>
> [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...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Opposite and many to many
Next Topic:EMF Localization questions
Goto Forum:
  


Current Time: Fri Apr 26 15:47:11 GMT 2024

Powered by FUDForum. Page generated in 0.03500 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top