简体   繁体   中英

EMF dangling reference when I save my model

I have created a model with EMF and I would like to be able to save my model with the editor and open it later. For the example let's say that my model has 3 classes: A, B, C and R. The R is the root parent. The class C has a reference to A and one to B. When I edit my model everything works fine. But if I want to save my file to another location, I can open it but I can't save it anymore without getting an error message telling me that my references in my C object are dangling references. The xml file when saving looks like this for my reference:

<refToA ="//@CompElement.0/@composit/@parts.0">

I tried to set containable to true in my ecore file. Dangling references disappear but after a save if I touch attribute of B that the changement doesn't apply to the reference because now I have two B object.

How can I make properly a reference and save it ?

my model has 3 classes: A, B, C and R

you mean your metamodel has 3 EClasses/metaclasses A, B, C and R.

The R is the root parent

The root element of your model is of type R. How are A, B and C contained?

When I edit my model everything works fine. But if I want to save my file to another location, I can open it but I can't save it anymore

I doubt simply saving your Resource to a location or another has a significant impact on your model. How are you editing it and saving it to another location?

I found the solution. in my XMI file model was saved like this :

<R>
  <C refA... refB...>
  <\C>
  <A><\A>
  <B><\B>
<\R>

reference need to be place after saving A and B object like this :

<R>
  <A><\A>
  <B><\B>
  <C refA... refB...>
  <\C>
<\R>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM