Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Setting a reference as eOpposite of itself?
Setting a reference as eOpposite of itself? [message #428197] Fri, 13 March 2009 14:00 Go to next message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Hi all,

I wonder if it is possible to set an eReference itself from an eClass to itself as eOpposite.
Huh, this sounds strange; here is a simple example model:

EClass Box
- reference: Box relates (0..*) (eOpposite cannot be set, but I want it to be 'relates')

In the end, I would like to create many Boxes, some of them relating to each other; this relation should be in both directions. I.e. if I have two instances, boxA and boxB:

boxA.relates = List []
boxB.relates = List []

If something like boxA.getRelates().add(boxB) should result in:

boxA.relates = List [boxB]
boxB.relates = List [boxA]

Is that possible automatically or do I have to code it myself?

Cheers
Patrick
Re: Setting a reference as eOpposite of itself? [message #428199 is a reply to message #428197] Fri, 13 March 2009 14:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Patrick,

Comments below.


Patrick Könemann wrote:
> Hi all,
>
> I wonder if it is possible to set an eReference itself from an eClass
> to itself as eOpposite.
No, this discussion has come up a few times before. A bidirectional
reference in EMOF is a specialization of an association in CMOF and in
CMOF an association's ends must be two different properties.
> Huh, this sounds strange; here is a simple example model:
>
> EClass Box
> - reference: Box relates (0..*) (eOpposite cannot be set, but I want
> it to be 'relates')
>
> In the end, I would like to create many Boxes, some of them relating
> to each other; this relation should be in both directions. I.e. if I
> have two instances, boxA and boxB:
>
> boxA.relates = List []
> boxB.relates = List []
>
> If something like boxA.getRelates().add(boxB) should result in:
>
> boxA.relates = List [boxB]
> boxB.relates = List [boxA]
>
> Is that possible automatically or do I have to code it myself?
It's even very tricky to try to implement it. Especially consider that
a box might be related to itself...
>
> Cheers
> Patrick


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Setting a reference as eOpposite of itself? [message #428201 is a reply to message #428199] Fri, 13 March 2009 14:43 Go to previous message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Hi Ed,

Thanks for the quick reply.
At least for my case it would not be a big deal adding e.g. boxA to itself, there just needs to be a check that the add opposite is not called if the added element is itself, if I see it correctly.
So I guess I just change my generated code accordingly ;-)

Have a good weekend!
Patrick


On 13-03-2009 15:35, Ed Merks wrote:
> Patrick,
>
> Comments below.
>
>
> Patrick Könemann wrote:
>> Hi all,
>>
>> I wonder if it is possible to set an eReference itself from an eClass
>> to itself as eOpposite.
> No, this discussion has come up a few times before. A bidirectional
> reference in EMOF is a specialization of an association in CMOF and in
> CMOF an association's ends must be two different properties.
>> Huh, this sounds strange; here is a simple example model:
>>
>> EClass Box
>> - reference: Box relates (0..*) (eOpposite cannot be set, but I want
>> it to be 'relates')
>>
>> In the end, I would like to create many Boxes, some of them relating
>> to each other; this relation should be in both directions. I.e. if I
>> have two instances, boxA and boxB:
>>
>> boxA.relates = List []
>> boxB.relates = List []
>>
>> If something like boxA.getRelates().add(boxB) should result in:
>>
>> boxA.relates = List [boxB]
>> boxB.relates = List [boxA]
>>
>> Is that possible automatically or do I have to code it myself?
> It's even very tricky to try to implement it. Especially consider that a
> box might be related to itself...
>>
>> Cheers
>> Patrick
Previous Topic:[Teneo] Integrate EMF with Hibernate EntityManager persistence
Next Topic:Problem with cross-document serialization
Goto Forum:
  


Current Time: Fri Apr 19 04:04:37 GMT 2024

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

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

Back to the top