Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serialization of a relationship.
Serialization of a relationship. [message #418375] Mon, 14 April 2008 23:04 Go to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
Hi All,

I have this xsd to describe a simple bi-directional relationship.

<xsd:schema
xmlns:com.ibm.example.connection="http:///com/ibm/example/connection.ecore"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
ecore:nsPrefix="com.ibm.example.connection"
ecore:package="com.ibm.example.connection"
targetNamespace="http:///com/ibm/example/connection.ecore">

<xsd:complexType name="Parent">
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Table(name=PARENT)
</xsd:appinfo></xsd:annotation>
<xsd:sequence>

<xsd:element type="xsd:int" name="id">
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=AUTO) @Column(name="ID" unique="true")
</xsd:appinfo></xsd:annotation>
</xsd:element>

<xsd:element maxOccurs="1" minOccurs="0"
name="OneChildKnowsParentYes"
type="com.ibm.example.connection:OneChildKnowsParentYes"
ecore:opposite="parent"
>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@OneToOne(fetch=LAZY)
</xsd:appinfo></xsd:annotation>
</xsd:element>
</xsd:complexType>


<xsd:complexType name="OneChildKnowsParentYes">
<xsd:annotation><xsd:appinfo
source="teneo.jpa">@Table(name="C1PY")</xsd:appinfo></xsd:annotation >
<xsd:sequence>

<xsd:element type="xsd:int" name="id">
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=AUTO) @Column(name="ID")
</xsd:appinfo></xsd:annotation>
</xsd:element>

<xsd:element type="xsd:anyURI"
name="parent"
ecore:reference="com.ibm.example.connection:Parent"
ecore:opposite="OneChildKnowsParentYes"
>
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@OneToOne @JoinColumn(name="PARENT")
</xsd:appinfo></xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>

It's intended to be a completely normal bi-directional relationship
where the parent usually contains child. However, sometimes I serialize
the child without the parent, so I need the child to output the <parent>
tag with a URL in it. I just get:

<com.ibm.example.connection:OneChildKnowsParentYes>
<id>65536</id>
<data>BBB</data>
<!-- I need to have a 'parent' tag with a URI here -->
</com.ibm.example.connection:OneChildKnowsParentYes>

So far nothing I've tried will make the child print the parent. I can
see that the child knows the parent by calling child.getParent() and
getting the correct result before I serialize. I can also confirm that
the relationship is stored correctly in the database. It's just the XML
serialization that doesn't work.

Am I missing some option to make it write the URL?

Thanks for your help,

Jason Henriksen
Re: Serialization of a relationship. [message #418379 is a reply to message #418375] Mon, 14 April 2008 23:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060309050103030305020106
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jason,

It sounds like you are trying to get cross resource containment to work
with an XSD-based model, but it's never been designed to work for an
XSD-based model. E.g., XMLSaveImpl is guarded like this:

protected boolean writeTopElements(EObject top)
{
if (!*useEncodedAttributeStyle*)
{
InternalEObject container =
((InternalEObject)top).eInternalContainer();
if (container != null)
{
EReference containmentReference = top.eContainmentFeature();
EReference containerReference =
containmentReference.getEOpposite();
if (containerReference != null &&
!containerReference.isTransient())
{
saveHref(container, containerReference);
return true;
}
}
}
return false;
}

A question that I wouldn't know how to answer is: how would the parent
serialized its cross resource contained reference to the child?


jason henriksen wrote:
> Hi All,
>
> I have this xsd to describe a simple bi-directional relationship.
>
> <xsd:schema
> xmlns:com.ibm.example.connection="http:///com/ibm/example/connection.ecore"
>
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> ecore:nsPrefix="com.ibm.example.connection"
> ecore:package="com.ibm.example.connection"
> targetNamespace="http:///com/ibm/example/connection.ecore">
>
> <xsd:complexType name="Parent">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Table(name=PARENT)
> </xsd:appinfo></xsd:annotation>
> <xsd:sequence>
>
> <xsd:element type="xsd:int" name="id">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=AUTO) @Column(name="ID" unique="true")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
>
> <xsd:element maxOccurs="1" minOccurs="0"
> name="OneChildKnowsParentYes"
> type="com.ibm.example.connection:OneChildKnowsParentYes"
> ecore:opposite="parent"
> >
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne(fetch=LAZY)
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:complexType>
>
>
> <xsd:complexType name="OneChildKnowsParentYes">
> <xsd:annotation><xsd:appinfo
> source="teneo.jpa">@Table(name="C1PY")</xsd:appinfo></xsd:annotation >
> <xsd:sequence>
>
> <xsd:element type="xsd:int" name="id">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=AUTO) @Column(name="ID")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
>
> <xsd:element type="xsd:anyURI"
> name="parent"
> ecore:reference="com.ibm.example.connection:Parent"
> ecore:opposite="OneChildKnowsParentYes"
> >
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @OneToOne @JoinColumn(name="PARENT")
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
> It's intended to be a completely normal bi-directional relationship
> where the parent usually contains child. However, sometimes I
> serialize the child without the parent, so I need the child to output
> the <parent> tag with a URL in it. I just get:
>
> <com.ibm.example.connection:OneChildKnowsParentYes>
> <id>65536</id>
> <data>BBB</data>
> <!-- I need to have a 'parent' tag with a URI here -->
> </com.ibm.example.connection:OneChildKnowsParentYes>
>
> So far nothing I've tried will make the child print the parent. I can
> see that the child knows the parent by calling child.getParent() and
> getting the correct result before I serialize. I can also confirm
> that the relationship is stored correctly in the database. It's just
> the XML serialization that doesn't work.
>
> Am I missing some option to make it write the URL?
>
> Thanks for your help,
>
> Jason Henriksen


--------------060309050103030305020106
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jason,<br>
<br>
It sounds like you are trying to get cross resource containment to work
with an XSD-based model, but it's never been designed to work for an
XSD-based model. E.g., XMLSaveImpl is guarded like this:<small><br>
</small>
<blockquote><small>&nbsp; protected boolean writeTopElements(EObject top)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; if (!<b>useEncodedAttributeStyle</b>)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalEObject container =
((InternalEObject)top).eInternalContainer();</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (container != null)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; EReference containmentReference =
top.eContainmentFeature();</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; EReference containerReference =
containmentReference.getEOpposite();</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (containerReference != null &amp;&amp;

!containerReference.isTransient())</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveHref(container, containerReference);</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; return false;</small><br>
<small>&nbsp; }</small><br>
</blockquote>
A question that I wouldn't know how to answer is: how would the parent
serialized its cross resource contained reference to the child?<br>
<br>
<br>
jason henriksen wrote:
<blockquote cite="mid:fu0nul$tv9$1@build.eclipse.org" type="cite">Hi
All,
<br>
<br>
I have this xsd to describe a simple bi-directional relationship.
<br>
<br>
&lt;xsd:schema
<br>
xmlns:com.ibm.example.connection=<a class="moz-txt-link-rfc2396E" href="http:///com/ibm/example/connection.ecore">"http:///com/ibm/example/connection.ecore"</a>
<br>
xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a>
<br>
xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
<br>
ecore:nsPrefix="com.ibm.example.connection"
<br>
ecore:package="com.ibm.example.connection"
<br>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http:///com/ibm/example/connection.ecore">"http:///com/ibm/example/connection.ecore"</a>&gt;
<br>
<br>
&lt;xsd:complexType name="Parent"&gt;
<br>
&nbsp;&lt;xsd:annotation&gt;&lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;@Table(name=PARENT)
<br>
&nbsp;&lt;/xsd:appinfo&gt;&lt;/xsd:annotatio n&gt;
<br>
&lt;xsd:sequence&gt;
<br>
<br>
&nbsp;&lt;xsd:element type="xsd:int" name="id"&gt;
<br>
&nbsp; &lt;xsd:annotation&gt;&lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp; @Id @GeneratedValue(strategy=AUTO) @Column(name="ID" unique="true")
<br>
&nbsp; &lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
<br>
&nbsp;&lt;/xsd:element&gt;
<br>
<br>
&nbsp;&lt;xsd:element maxOccurs="1" minOccurs="0"
<br>
&nbsp; name="OneChildKnowsParentYes"
<br>
&nbsp; type="com.ibm.example.connection:OneChildKnowsParentYes"
<br>
&nbsp; ecore:opposite="parent" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&gt;
<br>
&nbsp; &lt;xsd:annotation&gt;&lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp; @OneToOne(fetch=LAZY)
<br>
&nbsp; &lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
<br>
&nbsp;&lt;/xsd:element&gt;
<br>
&lt;/xsd:complexType&gt;
<br>
<br>
<br>
&lt;xsd:complexType name="OneChildKnowsParentYes"&gt;
<br>
&nbsp;&lt;xsd:annotation&gt;&lt;xsd:appinfo
source="teneo.jpa"&gt;@Table(name="C1PY" )&lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
<br>
&nbsp;&lt;xsd:sequence&gt;
<br>
<br>
&nbsp;&lt;xsd:element type="xsd:int" name="id"&gt;
<br>
&nbsp; &lt;xsd:annotation&gt;&lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=AUTO) @Column(name="ID")
<br>
&nbsp; &lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
<br>
&nbsp;&lt;/xsd:element&gt;
<br>
<br>
&nbsp;&lt;xsd:element type="xsd:anyURI"
<br>
&nbsp; name="parent"
<br>
&nbsp; ecore:reference="com.ibm.example.connection:Parent"
<br>
&nbsp; ecore:opposite="OneChildKnowsParentYes"
<br>
&nbsp;&gt;
<br>
&nbsp; &lt;xsd:annotation&gt;&lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp; @OneToOne @JoinColumn(name="PARENT")
<br>
&nbsp; &lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
<br>
&nbsp;&lt;/xsd:element&gt;
<br>
&lt;/xsd:sequence&gt;
<br>
&lt;/xsd:complexType&gt;
<br>
<br>
&lt;/xsd:schema&gt;
<br>
<br>
It's intended to be a completely normal bi-directional relationship
where the parent usually contains child.&nbsp; However, sometimes I
serialize the child without the parent, so I need the child to output
the &lt;parent&gt; tag with a URL in it.&nbsp; I just get:
<br>
<br>
&lt;com.ibm.example.connection:OneChildKnowsParentYes&am p;gt;
<br>
&nbsp; &lt;id&gt;65536&lt;/id&gt;
<br>
&nbsp; &lt;data&gt;BBB&lt;/data&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;!-- I need to have a 'parent' tag with a URI here --&gt;
<br>
&lt;/com.ibm.example.connection:OneChildKnowsParentYes&a mp;gt;
<br>
<br>
So far nothing I've tried will make the child print the parent.&nbsp; I can
see that the child knows the parent by calling child.getParent() and
getting the correct result before I serialize.&nbsp; I can also confirm that
the relationship is stored correctly in the database.&nbsp; It's just the
XML serialization that doesn't work.
<br>
<br>
Am I missing some option to make it write the URL?
<br>
<br>
Thanks for your help,
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Jason Henriksen
<br>
</blockquote>
<br>
</body>
</html>

--------------060309050103030305020106--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Backwards-compatible export of EMF 2.4-based resources (e.g., *.uml) to EMF 2.3-compatible resources
Next Topic:Notification when emf model is loaded
Goto Forum:
  


Current Time: Thu Apr 25 12:10:59 GMT 2024

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

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

Back to the top