Take the 2-minute tour ×

Is that true that there is only Composition relation in EMF? Or there is a way to create an aggregation relation between my model?


share|improve this question

3 Answers 3

up vote 0 down vote accepted

As soon as you are working with association it is better to avoid the use of EMF.

share|improve this answer
Why? this is not clear, can you detail please –  TheCyberXP Apr 25 '12 at 9:40
The association property should be owned by the targeted classifier and saved as an attribute in UML2. As soon as you can not define full UML association property with EMF then this is useless. EMF is java code oriented and in Java you don't have a difference between aggregation and composition. It is only at model or graphical level that you can see it. Hope this help :-) –  UML GURU Apr 25 '12 at 14:02

Is that true that there is only Composition relation in EMF?

Kind of. The only way to define an association in EMF is to use an EReference (actually, a pair of them to be precise - one each way). EReference has a flag for 'Containment'. It's used by EMF during generation: for example, in the generated EMF editor, containment=true allows you to create child nodes of the referenced type. If not you can only refer to them.

However: the more pertinent question is: what do you mean by Aggregation vs. Composition? Aggregation is so loosely defined in UML that everyone has their own interpretation.

Perhaps you could say more about the rules you want to express with Aggregation vs Composition?


share|improve this answer
well I will explain my problem with a kind of example. Assume that we have 3 Models : Room, Wall, Chair. The relation {Room, Wall} is a composition relation (the wall can't "live" without a room) but the relation {Room, Chair} is an aggregation we can instantiate separately a room and a chair, and I didn't find how to express this kind of relation in EMF. In UML it is represented by an empty/white lozenge but the composition is represented by a dark/full lozenge. is that clear? –  TheCyberXP Apr 24 '12 at 11:46
OK that helps. Two things then. (1) I really don't think you need Aggregation. You have a simple binary relationship. Aggregation in UML is a dog of a thing - the semantics are so weak it offers no value in practice over a straight binary. So tha leads to point (2): just use an EReference with containment set to false for {Room, Chair}. hth. –  sfinnie Apr 24 '12 at 13:18

As i remember, it's possible ... i don't have the plugins anymore ...

Take a look HERE , section 3.2. Create Ecore diagram

share|improve this answer
This not what I need, my question is about the different kind of relation in EMF, and it appear that there is only 3: a simple relation (EReferences, Composition (containment), inheritances) and I'm searching how to make the aggregation. But thank you anyway ;) –  TheCyberXP Apr 24 '12 at 11:54
I think that when the EReference.containment = True the reference is considered as Composition "Any parent object which has a containment reference (containment=true in the EMF metamodel) to a child object manages the lifecycle of that child" Else it will be considered as an aggregation. –  Mehdi Apr 24 '12 at 12:24
the first part is ok, but your "else" part no :) it will be considered like a simple relation. That's why I'm asking how to make the aggregation –  TheCyberXP Apr 24 '12 at 12:28
I think that you should make the difference between META Modelling and Modelling, you are talking about UML concepts (Association, Aggregation and Composition) ... There is no EXACT equivalent in EMF, because it's a higher Level, UML can be designed using EMF ... in EMF you create your own Concepts : Relation A (Association), Relation B (Aggregation) ... for that you will just the more generic concepts (Relation/Multiplicity ...) –  Mehdi Apr 24 '12 at 13:16
pretty clear and here come the big problem: I have to export a metamodel from Magic Draw and import it into EMF, I can see my model but no way to instantiate it, because of many error and ambiguities handled by EMF that's why I'm thinking to change the metamodel and adopt it to EMF but before doing that I have to prove the problem! –  TheCyberXP Apr 24 '12 at 13:24

Your Answer


