Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to correctly save cross-referenced models to XMI(No href tags are generated with my approach)
How to correctly save cross-referenced models to XMI [message #1738678] Fri, 22 July 2016 08:01 Go to next message
HN Hindriks is currently offline HN HindriksFriend
Messages: 6
Registered: July 2016
Junior Member
I have two models: A.ecore and B.ecore, where B.ecore specifies that some classes reference classes from A.ecore.

I am working in Java, and I created an instance of A.ecore (let's call it _a) using generated Java classes, and managed to serialize it to XMI, using XMIResourceFactoryImpl.
Afterwards, I am able to correctly deserialize the saved file and obtain my Java classes.

Now I am working on an instance of B.ecore (_b), which contains instances which reference instances from _a. This is again specified using Java, where I explicitly assign some instance of _a from an instance in _b.

While testing the serialization of _b, I first saved _b using XMIResourceFactoryImpl, which succeeds (at least, it does not crash).
Next, I try to load _b again using a new instance of XMIResourceFactoryImpl. But this time I run into the following exception:
Exception in thread "main" org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Unresolved reference '-7035880107558485299'. (file:/..., 3, 143)


When manually inspecting the generated files I noticed the following things:
1.The object with id '-7035880107558485299' actually exists in _a
2.The generated XMI file of _b does not contain any reference to the XMI file of _a, or any references to the metamodel of A.ecore.
<pvaiTypes xsi:type="SomeType" name="WithSomeName" UUID="-7401392374656186988" definition="-7035880107558485299">
...
</pvaiTypes>


Does anyone have a clue on what I'm doing wrong here?

Note that I use my own generated id's (random signed longs) for each instance in _a and _b. I guess what I'm doing should be possible in some way, but currently I fail to see how.
Re: How to correctly save cross-referenced models to XMI [message #1738881 is a reply to message #1738678] Mon, 25 July 2016 16:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Comments below.


On 25.07.2016 18:16, HN Hindriks wrote:
> I have two models: A.ecore and B.ecore, where B.ecore specifies that
> some classes reference classes from A.ecore.
>
> I am working in Java, and I created an instance of A.ecore (let's call
> it _a) using generated Java classes, and managed to serialize it to
> XMI, using XMIResourceFactoryImpl.
> Afterwards, I am able to correctly deserialize the saved file and
> obtain my Java classes.
>
> Now I am working on an instance of B.ecore (_b), which contains
> instances which reference instances from _a. This is again specified
> using Java, where I explicitly assign some instance of _a from an
> instance in _b.
>
> While testing the serialization of _b, I first saved _b using
> XMIResourceFactoryImpl, which succeeds (at least, it does not crash).
> Next, I try to load _b again using a new instance of
> XMIResourceFactoryImpl. But this time I run into the following exception:
> Exception in thread "main"
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Unresolved
> reference '-7035880107558485299'. (file:/..., 3, 143)
>
> When manually inspecting the generated files I noticed the following
> things:
> 1.The object with id '-7035880107558485299' actually exists in _a
You never mentioned serializing _a. Is it serialized? Note that it's
important that both _a and _b have complete structure before you
serailize them and that you set absolute URIs on the resource.
> 2.The generated XMI file of _b does not contain any reference to the
> XMI file of _a, or any references to the metamodel of A.ecore.
> <pvaiTypes xsi:type="SomeType" name="WithSomeName"
> UUID="-7401392374656186988" definition="-7035880107558485299">
It appears that the referenced "definition" is (must be) in the same
resource.
> ..
> </pvaiTypes>
>
>
> Does anyone have a clue on what I'm doing wrong here?
>
> Note that I use my own generated id's (random signed longs) for each
> instance in _a and _b. I guess what I'm doing should be possible in
> some way, but currently I fail to see how.
And you've built the full structure of _a and _b and serialized them
both after that?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to correctly save cross-referenced models to XMI [message #1738920 is a reply to message #1738881] Tue, 26 July 2016 07:27 Go to previous messageGo to next message
HN Hindriks is currently offline HN HindriksFriend
Messages: 6
Registered: July 2016
Junior Member
Hi Ed,

Thank you for the reply, and sorry for the double topics (this is the oldest of the two).
I already managed to resolve this problem.


To detail it for other users, and to answer your questions:

I have _a in both serialized and unserialized form. The URI's are absolute.
_a and _b are also complete (no unreferenced objects, and all relations with multiplicity >0 populated)

I resolved this by calling unload() on the Resource which contains _a. This replaces all references to _a in _b by proxy references.
Saving at this point results in 'href' tags being correctly generated.

[Updated on: Tue, 26 July 2016 07:27]

Report message to a moderator

Re: How to correctly save cross-referenced models to XMI [message #1739025 is a reply to message #1738920] Wed, 27 July 2016 04:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Without knowing the model details, it's hard to say what's wrong. The
generated getter for a proxy resolving single-valued reference generally
looks like this:


public ProjectContainer getLogicalProjectContainer()
{
if (logicalProjectContainer != null &&
logicalProjectContainer.eIsProxy())
{
InternalEObject oldLogicalProjectContainer =
(InternalEObject)logicalProjectContainer;
logicalProjectContainer =
(ProjectContainer)eResolveProxy(oldLogicalProjectContainer);
if (logicalProjectContainer != oldLogicalProjectContainer)
{
if (eNotificationRequired())
{
eNotify(new ENotificationImpl(this, Notification.RESOLVE,
SetupPackage.PROJECT__LOGICAL_PROJECT_CONTAINER, oldLogicalProjectContainer,
logicalProjectContainer));
}
}
}
return logicalProjectContainer;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ProjectContainer basicGetLogicalProjectContainer()
{
return logicalProjectContainer;
}

Where the eResolveProxy method is like this:

public EObject eResolveProxy(InternalEObject proxy)
{
return EcoreUtil.resolve(proxy, this);
}

So what you show you're doing manually should happen automatically in
this generated code.

But now you mention unloading something suggesting your serialization
was wrong. I'm not sure what to make of that.


On 26.07.2016 09:27, HN Hindriks wrote:
> Hi Ed,
>
> Thank you for the reply, and sorry for the double topics (this is the
> oldest of the two).
> I already managed to resolve this problem.
>
> To detail it for other users, and to answer your questions:
>
> I have _a in both serialized and unserialized form. The URI's are
> absolute.
> _a and _b are also complete (no unreferenced objects, and all
> relations with multiplicity >0 populated)
>
> I resolved this by calling unload() on the Resource which contains _a.
> This replaces all references to _a in _b by proxy references.
> Saving at this point results in 'href' tags being correctly generated.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Very basic question to first use of EEF
Next Topic:Additional Namespaces when saving an XMLResource
Goto Forum:
  


Current Time: Thu Apr 25 16:06:56 GMT 2024

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

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

Back to the top