javaeclipsercpeclipse-emf

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 ?


Solution

  • 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>