|
Re: Opposite reference unset after resolve [message #644165 is a reply to message #644144] |
Thu, 09 December 2010 17:39 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Julien,
Comments below.
Julien Bigot wrote:
> Hi,
>
> I'm loading a model instance from files, partially XMI, partially
> using a DSL with xtext.
>
> In this model, I have two classes (A and B) referencing each other
> though a bidirectional relation (with EOpposite reference set) through
> ref r1 & r2.
>
> A.r1<---->r2.B
>
> When parsing the model, an object "a" of the class "A" is read from
> one resource and an object "b" of class "B" from another resource.
> In this resource, b.r1 is set to reference a. At this time, this is
> however only a proxy.
There must be proxies on both ends. Resolving a proxy has no effect on
the opposite; it's assumed to hold a proxy that resolves independently.
>
> Res1:
> A: a (r1=null)
>
> Res2
> B: b (r2=aProxy)
> AProxy: aProxy (r1=b)
>
> Then proxy are resolved with a call to EcoreUtil.resolveAll and the
> proxy "aProxy" is replaced by the actual object "a". However this
> processes doesn't ensure the opposite relation.
Indeed. That's why we constrain opposites that are proxy resolving to
both be non-transient. I.e., both ends must serialize proxies.
>
> Res1:
> A: a (r1=null)
>
> Res2:
> B: b (r2=a)
>
> Is there a way I can ensure the opposite relationship ?
Ensure that the relationship is explicit in both resources. If you
can't do that, you really shouldn't have bidirectional references. You
might argue, but I really want them. In fact, many a time folks have
asked "why doesn't EClass.eSuperTypes have an opposite?" "It would be
so useful to know all derived classes. Indeed it would, but given a
class, it's impossible to know all derived classes, because a class
doesn't store references to all derived classes and it wouldn't make for
very predictable behavior if the set of derived classes just grew
whenever a new class shows up and resolves its eSuperType proxy...
> Tanks in advance.
>
> Regard,
> Julien
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02677 seconds