Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] 0..* associations, how to fetch parent from child
[Teneo] 0..* associations, how to fetch parent from child [message #422531] Mon, 08 September 2008 16:57 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

When you have a 0..* association the source code for the child does not
get generated with a convenience method to get the parent. We have to go
to the parent and use the getChild() method then iterate through the
EList returned looking for the child we are dealing with. E.g.

<xsd:complexType name="IssuerClass">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded"
ref="gensec:instrumentDomain" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="issuerClass" type="gensec:IssuerClass" />

<xsd:complexType name="InstrumentDomain">
<xsd:sequence>
<xsd:element maxOccurs="unbounded"
ref="gensec:instrumentIdentifier" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="shortName" type="xsd:string" />
</xsd:complexType>
<xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />


Will generate code with
EList<InstrumentDomain> getInstrumentDomain();
in IssuerClass. But nothing in the class InstrumentDomain to find its
IssuerClass, if it has one. This makes for very awkward coding when you
are passed a InstrumentDomain object.

I looked in the annotations to see if there was anything to allow me to
add this lookup of the parent in these one to many associations, could
not see it. Is there anything?

Thx.

David
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422533 is a reply to message #422531] Mon, 08 September 2008 17:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The eContainer() method should give you the parent in this case. You can also explicitly model the
assocation back from the instrumentDomain to the IssuerClass, and set the eopposite, you can use the
ecore:opposite attribute for that (see here
http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)

gr. Martin

David Wynter wrote:
> Hi,
>
> When you have a 0..* association the source code for the child does not
> get generated with a convenience method to get the parent. We have to go
> to the parent and use the getChild() method then iterate through the
> EList returned looking for the child we are dealing with. E.g.
>
> <xsd:complexType name="IssuerClass">
> <xsd:sequence>
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> ref="gensec:instrumentDomain" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>
> <xsd:complexType name="InstrumentDomain">
> <xsd:sequence>
> <xsd:element maxOccurs="unbounded"
> ref="gensec:instrumentIdentifier" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string" />
> <xsd:attribute name="shortName" type="xsd:string" />
> </xsd:complexType>
> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>
>
> Will generate code with
> EList<InstrumentDomain> getInstrumentDomain();
> in IssuerClass. But nothing in the class InstrumentDomain to find its
> IssuerClass, if it has one. This makes for very awkward coding when you
> are passed a InstrumentDomain object.
>
> I looked in the annotations to see if there was anything to allow me to
> add this lookup of the parent in these one to many associations, could
> not see it. Is there anything?
>
> Thx.
>
> David


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422541 is a reply to message #422533] Mon, 08 September 2008 22:41 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I added
<xsd:element minOccurs="0" maxOccurs="unbounded"
ref="gensec:instrumentDomain"
ecore:reference="gensec:InstrumentDomain" ecore:opposite="issuerClass"/>

But did not get the expected InstrumentDomain.getIssuerClass() method
generated? I also tried without the ecore:reference but got these weird
errors "the opposite of the opposite many not be a reference different
from this one"

I cannot use eContainer as the database schema has to be as unadorned as
is possible. Using eContainer adds 3 columns from what i read.

Regards,

David

Martin Taal wrote:
> Hi David,
> The eContainer() method should give you the parent in this case. You can
> also explicitly model the assocation back from the instrumentDomain to
> the IssuerClass, and set the eopposite, you can use the ecore:opposite
> attribute for that (see here
> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> When you have a 0..* association the source code for the child does
>> not get generated with a convenience method to get the parent. We have
>> to go to the parent and use the getChild() method then iterate through
>> the EList returned looking for the child we are dealing with. E.g.
>>
>> <xsd:complexType name="IssuerClass">
>> <xsd:sequence>
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> ref="gensec:instrumentDomain" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> </xsd:complexType>
>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>
>> <xsd:complexType name="InstrumentDomain">
>> <xsd:sequence>
>> <xsd:element maxOccurs="unbounded"
>> ref="gensec:instrumentIdentifier" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string" />
>> <xsd:attribute name="shortName" type="xsd:string" />
>> </xsd:complexType>
>> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>>
>>
>> Will generate code with
>> EList<InstrumentDomain> getInstrumentDomain();
>> in IssuerClass. But nothing in the class InstrumentDomain to find its
>> IssuerClass, if it has one. This makes for very awkward coding when
>> you are passed a InstrumentDomain object.
>>
>> I looked in the annotations to see if there was anything to allow me
>> to add this lookup of the parent in these one to many associations,
>> could not see it. Is there anything?
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422555 is a reply to message #422541] Tue, 09 September 2008 10:50 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Is it possible (taking your model into account) to add a xsd:element in InstrumentDomain which
points to IssuerClass (using an ecore:reference)? The ecore:opposite should be set in that
xsd:element and it should be the name of the efeature in IssuerClass which has the instrumentdomains
(in this case ecore:opposite="instrumentDomain" probably works).

gr. Martin

David Wynter wrote:
>
> Hi,
>
> I added
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> ref="gensec:instrumentDomain"
> ecore:reference="gensec:InstrumentDomain" ecore:opposite="issuerClass"/>
>
> But did not get the expected InstrumentDomain.getIssuerClass() method
> generated? I also tried without the ecore:reference but got these weird
> errors "the opposite of the opposite many not be a reference different
> from this one"
>
> I cannot use eContainer as the database schema has to be as unadorned as
> is possible. Using eContainer adds 3 columns from what i read.
>
> Regards,
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> The eContainer() method should give you the parent in this case. You
>> can also explicitly model the assocation back from the
>> instrumentDomain to the IssuerClass, and set the eopposite, you can
>> use the ecore:opposite attribute for that (see here
>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> When you have a 0..* association the source code for the child does
>>> not get generated with a convenience method to get the parent. We
>>> have to go to the parent and use the getChild() method then iterate
>>> through the EList returned looking for the child we are dealing with.
>>> E.g.
>>>
>>> <xsd:complexType name="IssuerClass">
>>> <xsd:sequence>
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> ref="gensec:instrumentDomain" />
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> </xsd:complexType>
>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>
>>> <xsd:complexType name="InstrumentDomain">
>>> <xsd:sequence>
>>> <xsd:element maxOccurs="unbounded"
>>> ref="gensec:instrumentIdentifier" />
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> <xsd:attribute name="name" type="xsd:string" />
>>> <xsd:attribute name="shortName" type="xsd:string" />
>>> </xsd:complexType>
>>> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>>>
>>>
>>> Will generate code with
>>> EList<InstrumentDomain> getInstrumentDomain();
>>> in IssuerClass. But nothing in the class InstrumentDomain to find its
>>> IssuerClass, if it has one. This makes for very awkward coding when
>>> you are passed a InstrumentDomain object.
>>>
>>> I looked in the annotations to see if there was anything to allow me
>>> to add this lookup of the parent in these one to many associations,
>>> could not see it. Is there anything?
>>>
>>> Thx.
>>>
>>> David
>>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422567 is a reply to message #422555] Tue, 09 September 2008 14:51 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Martin,

I added the suggested element and ended up with this:

<xsd:complexType name="IssuerClass">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded"
ref="gensec:instrumentDomain" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="issuerClass" type="gensec:IssuerClass" />

<xsd:complexType name="InstrumentDomain">
<xsd:sequence>
<xsd:element maxOccurs="unbounded"
ref="gensec:instrumentIdentifier" />
<xsd:element ecore:reference="gensec:IssuerClass"
ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
ref="gensec:instrumentDomain" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="shortName" type="xsd:string" />
</xsd:complexType>
<xsd:element name="instrumentDomain"
type="gensec:InstrumentDomain" />

It still did not generate a InstrumentDomain.getIssuerClass() method.

Regards,

David

Martin Taal wrote:
> Hi David,
> Is it possible (taking your model into account) to add a xsd:element in
> InstrumentDomain which points to IssuerClass (using an ecore:reference)?
> The ecore:opposite should be set in that xsd:element and it should be
> the name of the efeature in IssuerClass which has the instrumentdomains
> (in this case ecore:opposite="instrumentDomain" probably works).
>
> gr. Martin
>
> David Wynter wrote:
>>
>> Hi,
>>
>> I added
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> ref="gensec:instrumentDomain"
>> ecore:reference="gensec:InstrumentDomain" ecore:opposite="issuerClass"/>
>>
>> But did not get the expected InstrumentDomain.getIssuerClass() method
>> generated? I also tried without the ecore:reference but got these
>> weird errors "the opposite of the opposite many not be a reference
>> different from this one"
>>
>> I cannot use eContainer as the database schema has to be as unadorned
>> as is possible. Using eContainer adds 3 columns from what i read.
>>
>> Regards,
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> The eContainer() method should give you the parent in this case. You
>>> can also explicitly model the assocation back from the
>>> instrumentDomain to the IssuerClass, and set the eopposite, you can
>>> use the ecore:opposite attribute for that (see here
>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> When you have a 0..* association the source code for the child does
>>>> not get generated with a convenience method to get the parent. We
>>>> have to go to the parent and use the getChild() method then iterate
>>>> through the EList returned looking for the child we are dealing
>>>> with. E.g.
>>>>
>>>> <xsd:complexType name="IssuerClass">
>>>> <xsd:sequence>
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> ref="gensec:instrumentDomain" />
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> </xsd:complexType>
>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>
>>>> <xsd:complexType name="InstrumentDomain">
>>>> <xsd:sequence>
>>>> <xsd:element maxOccurs="unbounded"
>>>> ref="gensec:instrumentIdentifier" />
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> <xsd:attribute name="name" type="xsd:string" />
>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>> </xsd:complexType>
>>>> <xsd:element name="instrumentDomain"
>>>> type="gensec:InstrumentDomain" />
>>>>
>>>>
>>>> Will generate code with
>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>> in IssuerClass. But nothing in the class InstrumentDomain to find
>>>> its IssuerClass, if it has one. This makes for very awkward coding
>>>> when you are passed a InstrumentDomain object.
>>>>
>>>> I looked in the annotations to see if there was anything to allow me
>>>> to add this lookup of the parent in these one to many associations,
>>>> could not see it. Is there anything?
>>>>
>>>> Thx.
>>>>
>>>> David
>>>
>>>
>
>
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422568 is a reply to message #422567] Tue, 09 September 2008 15:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020002020509020100090905
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

David,

I think what you want is

<xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="unbounded" ref="lib:instrumentDomain" />


David Wynter wrote:
> Martin,
>
> I added the suggested element and ended up with this:
>
> <xsd:complexType name="IssuerClass">
> <xsd:sequence>
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> ref="gensec:instrumentDomain" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>
> <xsd:complexType name="InstrumentDomain">
> <xsd:sequence>
> <xsd:element maxOccurs="unbounded"
> ref="gensec:instrumentIdentifier" />
> <xsd:element ecore:reference="gensec:IssuerClass"
> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
> ref="gensec:instrumentDomain" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string" />
> <xsd:attribute name="shortName" type="xsd:string" />
> </xsd:complexType>
> <xsd:element name="instrumentDomain"
> type="gensec:InstrumentDomain" />
>
> It still did not generate a InstrumentDomain.getIssuerClass() method.
>
> Regards,
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> Is it possible (taking your model into account) to add a xsd:element
>> in InstrumentDomain which points to IssuerClass (using an
>> ecore:reference)? The ecore:opposite should be set in that
>> xsd:element and it should be the name of the efeature in IssuerClass
>> which has the instrumentdomains (in this case
>> ecore:opposite="instrumentDomain" probably works).
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>>
>>> Hi,
>>>
>>> I added
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> ref="gensec:instrumentDomain"
>>> ecore:reference="gensec:InstrumentDomain"
>>> ecore:opposite="issuerClass"/>
>>>
>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>> method generated? I also tried without the ecore:reference but got
>>> these weird errors "the opposite of the opposite many not be a
>>> reference different from this one"
>>>
>>> I cannot use eContainer as the database schema has to be as
>>> unadorned as is possible. Using eContainer adds 3 columns from what
>>> i read.
>>>
>>> Regards,
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> The eContainer() method should give you the parent in this case.
>>>> You can also explicitly model the assocation back from the
>>>> instrumentDomain to the IssuerClass, and set the eopposite, you can
>>>> use the ecore:opposite attribute for that (see here
>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> When you have a 0..* association the source code for the child
>>>>> does not get generated with a convenience method to get the
>>>>> parent. We have to go to the parent and use the getChild() method
>>>>> then iterate through the EList returned looking for the child we
>>>>> are dealing with. E.g.
>>>>>
>>>>> <xsd:complexType name="IssuerClass">
>>>>> <xsd:sequence>
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> ref="gensec:instrumentDomain" />
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> </xsd:complexType>
>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>
>>>>> <xsd:complexType name="InstrumentDomain">
>>>>> <xsd:sequence>
>>>>> <xsd:element maxOccurs="unbounded"
>>>>> ref="gensec:instrumentIdentifier" />
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>> </xsd:complexType>
>>>>> <xsd:element name="instrumentDomain"
>>>>> type="gensec:InstrumentDomain" />
>>>>>
>>>>>
>>>>> Will generate code with
>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>> in IssuerClass. But nothing in the class InstrumentDomain to find
>>>>> its IssuerClass, if it has one. This makes for very awkward coding
>>>>> when you are passed a InstrumentDomain object.
>>>>>
>>>>> I looked in the annotations to see if there was anything to allow
>>>>> me to add this lookup of the parent in these one to many
>>>>> associations, could not see it. Is there anything?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>>
>>
>>

--------------020002020509020100090905
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">
David,<br>
<br>
I think what you want is<br>
<blockquote>&lt;xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="unbounded" ref="lib:instrumentDomain" /&gt;<br>
</blockquote>
<br>
David Wynter wrote:
<blockquote cite="mid:ga62d0$h9m$1@build.eclipse.org" type="cite">Martin,
<br>
<br>
I added the suggested element and ended up with this:
<br>
<br>
&nbsp;&nbsp; &lt;xsd:complexType name="IssuerClass"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp;&nbsp; &lt;xsd:element name="issuerClass" type="gensec:IssuerClass" /&gt;
<br>
<br>
&nbsp;&nbsp; &lt;xsd:complexType name="InstrumentDomain"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element maxOccurs="unbounded"
<br>
&nbsp;ref="gensec:instrumentIdentifier" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element ecore:reference="gensec:IssuerClass"
ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="name" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="shortName" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp;&nbsp; &lt;xsd:element name="instrumentDomain"
<br>
&nbsp;type="gensec:InstrumentDomain" /&gt;
<br>
<br>
It still did not generate a InstrumentDomain.getIssuerClass() method.
<br>
<br>
Regards,
<br>
<br>
David
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Hi David,
<br>
Is it possible (taking your model into account) to add a xsd:element in
InstrumentDomain which points to IssuerClass (using an
ecore:reference)? The ecore:opposite should be set in that xsd:element
and it should be the name of the efeature in IssuerClass which has the
instrumentdomains (in this case ecore:opposite="instrumentDomain"
probably works).
<br>
<br>
gr. Martin
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite"><br>
Hi,
<br>
<br>
I added
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ref="gensec:instrumentDomain"
ecore:reference="gensec:InstrumentDomain"&nbsp;
ecore:opposite="issuerClass"/&gt;
<br>
<br>
But did not get the expected InstrumentDomain.getIssuerClass() method
generated? I also tried without the ecore:reference but got these weird
errors "the opposite of the opposite many not be a reference different
from this one"
<br>
<br>
I cannot use eContainer as the database schema has to be as unadorned
as is possible. Using eContainer adds 3 columns from what i read.
<br>
<br>
Regards,
<br>
<br>
David
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Hi David,
<br>
The eContainer() method should give you the parent in this case. You
can also explicitly model the assocation back from the instrumentDomain
to the IssuerClass, and set the eopposite, you can use the
ecore:opposite attribute for that (see here
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf"> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf</a>)
<br>
<br>
gr. Martin
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
When you have a 0..* association the source code for the child does not
get generated with a convenience method to get the parent. We have to
go to the parent and use the getChild() method then iterate through the
EList returned looking for the child we are dealing with. E.g.
<br>
<br>
&nbsp; &lt;xsd:complexType name="IssuerClass"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp; &lt;xsd:element name="issuerClass" type="gensec:IssuerClass" /&gt;
<br>
<br>
&nbsp; &lt;xsd:complexType name="InstrumentDomain"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element maxOccurs="unbounded"
ref="gensec:instrumentIdentifier" /&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="name" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="shortName" type="xsd:string" /&gt;
<br>
&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp; &lt;xsd:element name="instrumentDomain"
type="gensec:InstrumentDomain" /&gt;
<br>
<br>
<br>
Will generate code with
<br>
&nbsp;&nbsp;&nbsp; EList&lt;InstrumentDomain&gt; getInstrumentDomain();
<br>
in IssuerClass. But nothing in the class InstrumentDomain to find its
IssuerClass, if it has one. This makes for very awkward coding when you
are passed a InstrumentDomain object.
<br>
<br>
I looked in the annotations to see if there was anything to allow me to
add this lookup of the parent in these one to many associations, could
not see it. Is there anything?
<br>
<br>
Thx.
<br>
<br>
David
<br>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
</body>
</html>

--------------020002020509020100090905--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422570 is a reply to message #422568] Tue, 09 September 2008 15:56 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

There seems to be some confusion, lets say you have a parent 0..* child.
The standard xsd will generate a method for the parent to get all the
children. I simply want a method that for a child it will fetch its only
parent.

The element you suggested ended up adding the method with the right name
but it returns objects not of the type of the parent, in this case
IssuerClass, but of the type of the child, in the case InstrumentDomain.
So it appears to be a self referential relationship it set up.

I changed it to this.

<xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
ref="gensec:issuerClass" />

This does what I expect it to do in the InstrumentDomain class, adding
IssuerClass InstrumentDomain.getIssuerCLass()

but it adds a superflous method
InstrumentDomain IssuerClass.getIssuerClass();

I already have EList<InstrumentDomain> IssuerClass.getInstrumentDomain()

Which is the real one I need.

What I want is going to be required by a large proportion of developers.
Say I am presented an InstrumentDomain object and need to get its
IssuerClass, my current only option seems to be to resort to the native
SQL and use the foreign key in the table underlying InstrumentDomain to
get it.

David

Ed Merks wrote:
> David,
>
> I think what you want is
>
> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>
>
> David Wynter wrote:
>> Martin,
>>
>> I added the suggested element and ended up with this:
>>
>> <xsd:complexType name="IssuerClass">
>> <xsd:sequence>
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> ref="gensec:instrumentDomain" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> </xsd:complexType>
>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>
>> <xsd:complexType name="InstrumentDomain">
>> <xsd:sequence>
>> <xsd:element maxOccurs="unbounded"
>> ref="gensec:instrumentIdentifier" />
>> <xsd:element ecore:reference="gensec:IssuerClass"
>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>> ref="gensec:instrumentDomain" />
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string" />
>> <xsd:attribute name="shortName" type="xsd:string" />
>> </xsd:complexType>
>> <xsd:element name="instrumentDomain"
>> type="gensec:InstrumentDomain" />
>>
>> It still did not generate a InstrumentDomain.getIssuerClass() method.
>>
>> Regards,
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> Is it possible (taking your model into account) to add a xsd:element
>>> in InstrumentDomain which points to IssuerClass (using an
>>> ecore:reference)? The ecore:opposite should be set in that
>>> xsd:element and it should be the name of the efeature in IssuerClass
>>> which has the instrumentdomains (in this case
>>> ecore:opposite="instrumentDomain" probably works).
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>>
>>>> Hi,
>>>>
>>>> I added
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> ref="gensec:instrumentDomain"
>>>> ecore:reference="gensec:InstrumentDomain"
>>>> ecore:opposite="issuerClass"/>
>>>>
>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>> method generated? I also tried without the ecore:reference but got
>>>> these weird errors "the opposite of the opposite many not be a
>>>> reference different from this one"
>>>>
>>>> I cannot use eContainer as the database schema has to be as
>>>> unadorned as is possible. Using eContainer adds 3 columns from what
>>>> i read.
>>>>
>>>> Regards,
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> The eContainer() method should give you the parent in this case.
>>>>> You can also explicitly model the assocation back from the
>>>>> instrumentDomain to the IssuerClass, and set the eopposite, you can
>>>>> use the ecore:opposite attribute for that (see here
>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> When you have a 0..* association the source code for the child
>>>>>> does not get generated with a convenience method to get the
>>>>>> parent. We have to go to the parent and use the getChild() method
>>>>>> then iterate through the EList returned looking for the child we
>>>>>> are dealing with. E.g.
>>>>>>
>>>>>> <xsd:complexType name="IssuerClass">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> ref="gensec:instrumentDomain" />
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>
>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="instrumentDomain"
>>>>>> type="gensec:InstrumentDomain" />
>>>>>>
>>>>>>
>>>>>> Will generate code with
>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to find
>>>>>> its IssuerClass, if it has one. This makes for very awkward coding
>>>>>> when you are passed a InstrumentDomain object.
>>>>>>
>>>>>> I looked in the annotations to see if there was anything to allow
>>>>>> me to add this lookup of the parent in these one to many
>>>>>> associations, could not see it. Is there anything?
>>>>>>
>>>>>> Thx.
>>>>>>
>>>>>> David
>>>>>
>>>>>
>>>
>>>
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422571 is a reply to message #422570] Tue, 09 September 2008 16:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
David,

Comments below.

David Wynter wrote:
> Hi,
>
> There seems to be some confusion,
You think?
> lets say you have a parent 0..* child. The standard xsd will generate
> a method for the parent to get all the children. I simply want a
> method that for a child it will fetch its only parent.
I gathered that...
>
> The element you suggested ended up adding the method with the right
> name but it returns objects not of the type of the parent, in this
> case IssuerClass,
In InstrumentDomain I get:

IssuerClass getIssuerClass();

The IssuerClass contains the InstrumentDomain and the InstrumentDomain
has a method for accessing that parent. I'm not sure what I messed.
> but of the type of the child, in the case InstrumentDomain. So it
> appears to be a self referential relationship it set up.
>
> I changed it to this.
>
> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
> ref="gensec:issuerClass" />
Just the names tell me this can't possibly be right...
>
> This does what I expect it to do in the InstrumentDomain class, adding
> IssuerClass InstrumentDomain.getIssuerCLass()
This you get even without the opposite, right?
>
> but it adds a superflous method
> InstrumentDomain IssuerClass.getIssuerClass();
This is the part that's wrong because you aren't using opposite
appropriately.
>
> I already have EList<InstrumentDomain> IssuerClass.getInstrumentDomain()
>
> Which is the real one I need.
>
> What I want is going to be required by a large proportion of
> developers. Say I am presented an InstrumentDomain object and need to
> get its IssuerClass, my current only option seems to be to resort to
> the native SQL and use the foreign key in the table underlying
> InstrumentDomain to get it.
I think a wire got cross somewhere. If you want any of your containment
references to have an inverse (all elements referring to complex types
will result in containment references), then you put an ecore:opposite
on that element/element-ref and you give the name of the feature as it
will appear in the reference's type. So say I have a class Parent that
has an element "child" of type "Child", I would put
ecore:opposite="parent" on that element declaration in the Parent
complex type and as a result the Child EClass would end up with a
"parent" feature of type "Parent"...
>
> David
>
> Ed Merks wrote:
>> David,
>>
>> I think what you want is
>>
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>
>>
>> David Wynter wrote:
>>> Martin,
>>>
>>> I added the suggested element and ended up with this:
>>>
>>> <xsd:complexType name="IssuerClass">
>>> <xsd:sequence>
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> ref="gensec:instrumentDomain" />
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> </xsd:complexType>
>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>
>>> <xsd:complexType name="InstrumentDomain">
>>> <xsd:sequence>
>>> <xsd:element maxOccurs="unbounded"
>>> ref="gensec:instrumentIdentifier" />
>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>> ref="gensec:instrumentDomain" />
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> <xsd:attribute name="name" type="xsd:string" />
>>> <xsd:attribute name="shortName" type="xsd:string" />
>>> </xsd:complexType>
>>> <xsd:element name="instrumentDomain"
>>> type="gensec:InstrumentDomain" />
>>>
>>> It still did not generate a InstrumentDomain.getIssuerClass() method.
>>>
>>> Regards,
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Is it possible (taking your model into account) to add a
>>>> xsd:element in InstrumentDomain which points to IssuerClass (using
>>>> an ecore:reference)? The ecore:opposite should be set in that
>>>> xsd:element and it should be the name of the efeature in
>>>> IssuerClass which has the instrumentdomains (in this case
>>>> ecore:opposite="instrumentDomain" probably works).
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I added
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> ref="gensec:instrumentDomain"
>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>> ecore:opposite="issuerClass"/>
>>>>>
>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>> method generated? I also tried without the ecore:reference but got
>>>>> these weird errors "the opposite of the opposite many not be a
>>>>> reference different from this one"
>>>>>
>>>>> I cannot use eContainer as the database schema has to be as
>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>> what i read.
>>>>>
>>>>> Regards,
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> The eContainer() method should give you the parent in this case.
>>>>>> You can also explicitly model the assocation back from the
>>>>>> instrumentDomain to the IssuerClass, and set the eopposite, you
>>>>>> can use the ecore:opposite attribute for that (see here
>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> When you have a 0..* association the source code for the child
>>>>>>> does not get generated with a convenience method to get the
>>>>>>> parent. We have to go to the parent and use the getChild()
>>>>>>> method then iterate through the EList returned looking for the
>>>>>>> child we are dealing with. E.g.
>>>>>>>
>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>
>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>
>>>>>>>
>>>>>>> Will generate code with
>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>> find its IssuerClass, if it has one. This makes for very awkward
>>>>>>> coding when you are passed a InstrumentDomain object.
>>>>>>>
>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>> allow me to add this lookup of the parent in these one to many
>>>>>>> associations, could not see it. Is there anything?
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>
>>>>>>
>>>>
>>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422573 is a reply to message #422571] Tue, 09 September 2008 16:59 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Comments below. To clarify, IssuerClass is the parent and
InstrumentDomain is the child.

David
Ed Merks wrote:
> David,
>
> Comments below.
>
> David Wynter wrote:
>> Hi,
>>
>> There seems to be some confusion,
> You think?
>> lets say you have a parent 0..* child. The standard xsd will generate
>> a method for the parent to get all the children. I simply want a
>> method that for a child it will fetch its only parent.
> I gathered that...
>>
>> The element you suggested ended up adding the method with the right
>> name but it returns objects not of the type of the parent, in this
>> case IssuerClass,
> In InstrumentDomain I get:
>
> IssuerClass getIssuerClass();
>
> The IssuerClass contains the InstrumentDomain and the InstrumentDomain
> has a method for accessing that parent. I'm not sure what I messed.
>> but of the type of the child, in the case InstrumentDomain. So it
>> appears to be a self referential relationship it set up.
>>
>> I changed it to this.
>>
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
>> ref="gensec:issuerClass" />
> Just the names tell me this can't possibly be right...
>>
>> This does what I expect it to do in the InstrumentDomain class, adding
>> IssuerClass InstrumentDomain.getIssuerCLass()
> This you get even without the opposite, right?
No I got this with exactly what I showed there. For clarity as here:
<xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
ref="gensec:issuerClass" />
this is inside the InstrumentDomain complexType definition
>>
>> but it adds a superflous method
>> InstrumentDomain IssuerClass.getIssuerClass();
> This is the part that's wrong because you aren't using opposite
> appropriately.
OK that is clear to me
>>
>> I already have EList<InstrumentDomain> IssuerClass.getInstrumentDomain()
>>
>> Which is the real one I need.
>>
>> What I want is going to be required by a large proportion of
>> developers. Say I am presented an InstrumentDomain object and need to
>> get its IssuerClass, my current only option seems to be to resort to
>> the native SQL and use the foreign key in the table underlying
>> InstrumentDomain to get it.
> I think a wire got cross somewhere. If you want any of your containment
> references to have an inverse (all elements referring to complex types
> will result in containment references), then you put an ecore:opposite
> on that element/element-ref and you give the name of the feature as it
> will appear in the reference's type. So say I have a class Parent that
> has an element "child" of type "Child", I would put
> ecore:opposite="parent" on that element declaration in the Parent
> complex type and as a result the Child EClass would end up with a
> "parent" feature of type "Parent"...
I am now confused. Reading this makes me think I should add to the
element definition in IssuerClass complexType definition. Terminology is
a problem. So to clarify.
1. In this case the containment reference in IssuerClass is:
<xsd:element minOccurs="0" maxOccurs="unbounded"
ref="gensec:instrumentDomain" />
2. The feature name is thus "gensec:issuerClass"? (although "reference's
type" suggests to me the far end of this relationship)

When I tried this as the reference
<xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
maxOccurs="unbounded" ref="gensec:instrumentDomain" />

I got an error "The name "gensec:issuerClass" is not well formed"

Thx.


>>
>> David
>>
>> Ed Merks wrote:
>>> David,
>>>
>>> I think what you want is
>>>
>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>>
>>>
>>> David Wynter wrote:
>>>> Martin,
>>>>
>>>> I added the suggested element and ended up with this:
>>>>
>>>> <xsd:complexType name="IssuerClass">
>>>> <xsd:sequence>
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> ref="gensec:instrumentDomain" />
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> </xsd:complexType>
>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>
>>>> <xsd:complexType name="InstrumentDomain">
>>>> <xsd:sequence>
>>>> <xsd:element maxOccurs="unbounded"
>>>> ref="gensec:instrumentIdentifier" />
>>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>>> ref="gensec:instrumentDomain" />
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> <xsd:attribute name="name" type="xsd:string" />
>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>> </xsd:complexType>
>>>> <xsd:element name="instrumentDomain"
>>>> type="gensec:InstrumentDomain" />
>>>>
>>>> It still did not generate a InstrumentDomain.getIssuerClass() method.
>>>>
>>>> Regards,
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> Is it possible (taking your model into account) to add a
>>>>> xsd:element in InstrumentDomain which points to IssuerClass (using
>>>>> an ecore:reference)? The ecore:opposite should be set in that
>>>>> xsd:element and it should be the name of the efeature in
>>>>> IssuerClass which has the instrumentdomains (in this case
>>>>> ecore:opposite="instrumentDomain" probably works).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I added
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> ref="gensec:instrumentDomain"
>>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>>> ecore:opposite="issuerClass"/>
>>>>>>
>>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>>> method generated? I also tried without the ecore:reference but got
>>>>>> these weird errors "the opposite of the opposite many not be a
>>>>>> reference different from this one"
>>>>>>
>>>>>> I cannot use eContainer as the database schema has to be as
>>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>>> what i read.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> The eContainer() method should give you the parent in this case.
>>>>>>> You can also explicitly model the assocation back from the
>>>>>>> instrumentDomain to the IssuerClass, and set the eopposite, you
>>>>>>> can use the ecore:opposite attribute for that (see here
>>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>>
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> When you have a 0..* association the source code for the child
>>>>>>>> does not get generated with a convenience method to get the
>>>>>>>> parent. We have to go to the parent and use the getChild()
>>>>>>>> method then iterate through the EList returned looking for the
>>>>>>>> child we are dealing with. E.g.
>>>>>>>>
>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>> <xsd:sequence>
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>> </xsd:sequence>
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> </xsd:complexType>
>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>
>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>> <xsd:sequence>
>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>> </xsd:sequence>
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>> </xsd:complexType>
>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>
>>>>>>>>
>>>>>>>> Will generate code with
>>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>>> find its IssuerClass, if it has one. This makes for very awkward
>>>>>>>> coding when you are passed a InstrumentDomain object.
>>>>>>>>
>>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>>> allow me to add this lookup of the parent in these one to many
>>>>>>>> associations, could not see it. Is there anything?
>>>>>>>>
>>>>>>>> Thx.
>>>>>>>>
>>>>>>>> David
>>>>>>>
>>>>>>>
>>>>>
>>>>>
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422576 is a reply to message #422573] Tue, 09 September 2008 19:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
David,

Comments below.

David Wynter wrote:
> Hi,
>
> Comments below. To clarify, IssuerClass is the parent and
> InstrumentDomain is the child.
>
> David
> Ed Merks wrote:
>> David,
>>
>> Comments below.
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> There seems to be some confusion,
>> You think?
>>> lets say you have a parent 0..* child. The standard xsd will
>>> generate a method for the parent to get all the children. I simply
>>> want a method that for a child it will fetch its only parent.
>> I gathered that...
>>>
>>> The element you suggested ended up adding the method with the right
>>> name but it returns objects not of the type of the parent, in this
>>> case IssuerClass,
>> In InstrumentDomain I get:
>>
>> IssuerClass getIssuerClass();
>>
>> The IssuerClass contains the InstrumentDomain and the
>> InstrumentDomain has a method for accessing that parent. I'm not
>> sure what I messed.
>>> but of the type of the child, in the case InstrumentDomain. So it
>>> appears to be a self referential relationship it set up.
>>>
>>> I changed it to this.
>>>
>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>> maxOccurs="1" ref="gensec:issuerClass" />
>> Just the names tell me this can't possibly be right...
>>>
>>> This does what I expect it to do in the InstrumentDomain class,
>>> adding IssuerClass InstrumentDomain.getIssuerCLass()
>> This you get even without the opposite, right?
> No I got this with exactly what I showed there. For clarity as here:
> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
> ref="gensec:issuerClass" />
> this is inside the InstrumentDomain complexType definition
Using ecore:opposite will not create a feature in the class containing
this element declaration. So your getIssuerClass method is appearing
because of the element declaration, not because of the ecore:opposite
annotation.
>>>
>>> but it adds a superflous method
>>> InstrumentDomain IssuerClass.getIssuerClass();
>> This is the part that's wrong because you aren't using opposite
>> appropriately.
> OK that is clear to me
>>>
>>> I already have EList<InstrumentDomain>
>>> IssuerClass.getInstrumentDomain()
>>>
>>> Which is the real one I need.
>>>
>>> What I want is going to be required by a large proportion of
>>> developers. Say I am presented an InstrumentDomain object and need
>>> to get its IssuerClass, my current only option seems to be to resort
>>> to the native SQL and use the foreign key in the table underlying
>>> InstrumentDomain to get it.
>> I think a wire got cross somewhere. If you want any of your
>> containment references to have an inverse (all elements referring to
>> complex types will result in containment references), then you put an
>> ecore:opposite on that element/element-ref and you give the name of
>> the feature as it will appear in the reference's type. So say I have
>> a class Parent that has an element "child" of type "Child", I would
>> put ecore:opposite="parent" on that element declaration in the Parent
>> complex type and as a result the Child EClass would end up with a
>> "parent" feature of type "Parent"...
> I am now confused. Reading this makes me think I should add to the
> element definition in IssuerClass complexType definition.
Yes, that's what I showed. It would have been more clear had I shown it
in context:

<xsd:complexType name="IssuerClass">
<xsd:sequence>
<xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="unbounded"
ref="lib:instrumentDomain" />
</xsd:sequence>

> Terminology is a problem. So to clarify.
> 1. In this case the containment reference in IssuerClass is:
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> ref="gensec:instrumentDomain" />
Yes.
> 2. The feature name is thus "gensec:issuerClass"?
No, the feature name should just be a well formed Java identifier
representing the actual name of the EMF feature you want generated.
> (although "reference's type" suggests to me the far end of this
> relationship)
It will be a feature in the type of the element, i.e, InstrumentDomain.
>
> When I tried this as the reference
> <xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
> maxOccurs="unbounded" ref="gensec:instrumentDomain" />
>
> I got an error "The name "gensec:issuerClass" is not well formed"
Remove the "gensec:", and you should be golden.
>
> Thx.
>
>
>>>
>>> David
>>>
>>> Ed Merks wrote:
>>>> David,
>>>>
>>>> I think what you want is
>>>>
>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>>>
>>>>
>>>> David Wynter wrote:
>>>>> Martin,
>>>>>
>>>>> I added the suggested element and ended up with this:
>>>>>
>>>>> <xsd:complexType name="IssuerClass">
>>>>> <xsd:sequence>
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> ref="gensec:instrumentDomain" />
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> </xsd:complexType>
>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>
>>>>> <xsd:complexType name="InstrumentDomain">
>>>>> <xsd:sequence>
>>>>> <xsd:element maxOccurs="unbounded"
>>>>> ref="gensec:instrumentIdentifier" />
>>>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>>>> ref="gensec:instrumentDomain" />
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>> </xsd:complexType>
>>>>> <xsd:element name="instrumentDomain"
>>>>> type="gensec:InstrumentDomain" />
>>>>>
>>>>> It still did not generate a InstrumentDomain.getIssuerClass() method.
>>>>>
>>>>> Regards,
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> Is it possible (taking your model into account) to add a
>>>>>> xsd:element in InstrumentDomain which points to IssuerClass
>>>>>> (using an ecore:reference)? The ecore:opposite should be set in
>>>>>> that xsd:element and it should be the name of the efeature in
>>>>>> IssuerClass which has the instrumentdomains (in this case
>>>>>> ecore:opposite="instrumentDomain" probably works).
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I added
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> ref="gensec:instrumentDomain"
>>>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>>>> ecore:opposite="issuerClass"/>
>>>>>>>
>>>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>>>> method generated? I also tried without the ecore:reference but
>>>>>>> got these weird errors "the opposite of the opposite many not be
>>>>>>> a reference different from this one"
>>>>>>>
>>>>>>> I cannot use eContainer as the database schema has to be as
>>>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>>>> what i read.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> The eContainer() method should give you the parent in this
>>>>>>>> case. You can also explicitly model the assocation back from
>>>>>>>> the instrumentDomain to the IssuerClass, and set the eopposite,
>>>>>>>> you can use the ecore:opposite attribute for that (see here
>>>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>>>
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> When you have a 0..* association the source code for the child
>>>>>>>>> does not get generated with a convenience method to get the
>>>>>>>>> parent. We have to go to the parent and use the getChild()
>>>>>>>>> method then iterate through the EList returned looking for the
>>>>>>>>> child we are dealing with. E.g.
>>>>>>>>>
>>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>>> <xsd:sequence>
>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>>> </xsd:sequence>
>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>> </xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:attribute>
>>>>>>>>> </xsd:complexType>
>>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>>
>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>> <xsd:sequence>
>>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>>> </xsd:sequence>
>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>> </xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:attribute>
>>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>>> </xsd:complexType>
>>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Will generate code with
>>>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>>>> find its IssuerClass, if it has one. This makes for very
>>>>>>>>> awkward coding when you are passed a InstrumentDomain object.
>>>>>>>>>
>>>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>>>> allow me to add this lookup of the parent in these one to many
>>>>>>>>> associations, could not see it. Is there anything?
>>>>>>>>>
>>>>>>>>> Thx.
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422577 is a reply to message #422576] Tue, 09 September 2008 22:47 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I am golden, for a moment at least.

I added this ecore:opposite to other elements in the same complexType. I
am getting this error message.

"The opposite of opposite may not be a reference different from this one"

I checked for typos in the feature names. Am I allowed more than one of
the referenced elements to have the same feature name?

Thx.

David
"Ed Merks wrote:
> David,
>
> Comments below.
>
> David Wynter wrote:
>> Hi,
>>
>> Comments below. To clarify, IssuerClass is the parent and
>> InstrumentDomain is the child.
>>
>> David
>> Ed Merks wrote:
>>> David,
>>>
>>> Comments below.
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> There seems to be some confusion,
>>> You think?
>>>> lets say you have a parent 0..* child. The standard xsd will
>>>> generate a method for the parent to get all the children. I simply
>>>> want a method that for a child it will fetch its only parent.
>>> I gathered that...
>>>>
>>>> The element you suggested ended up adding the method with the right
>>>> name but it returns objects not of the type of the parent, in this
>>>> case IssuerClass,
>>> In InstrumentDomain I get:
>>>
>>> IssuerClass getIssuerClass();
>>>
>>> The IssuerClass contains the InstrumentDomain and the
>>> InstrumentDomain has a method for accessing that parent. I'm not
>>> sure what I messed.
>>>> but of the type of the child, in the case InstrumentDomain. So it
>>>> appears to be a self referential relationship it set up.
>>>>
>>>> I changed it to this.
>>>>
>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>> maxOccurs="1" ref="gensec:issuerClass" />
>>> Just the names tell me this can't possibly be right...
>>>>
>>>> This does what I expect it to do in the InstrumentDomain class,
>>>> adding IssuerClass InstrumentDomain.getIssuerCLass()
>>> This you get even without the opposite, right?
>> No I got this with exactly what I showed there. For clarity as here:
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
>> ref="gensec:issuerClass" />
>> this is inside the InstrumentDomain complexType definition
> Using ecore:opposite will not create a feature in the class containing
> this element declaration. So your getIssuerClass method is appearing
> because of the element declaration, not because of the ecore:opposite
> annotation.
>>>>
>>>> but it adds a superflous method
>>>> InstrumentDomain IssuerClass.getIssuerClass();
>>> This is the part that's wrong because you aren't using opposite
>>> appropriately.
>> OK that is clear to me
>>>>
>>>> I already have EList<InstrumentDomain>
>>>> IssuerClass.getInstrumentDomain()
>>>>
>>>> Which is the real one I need.
>>>>
>>>> What I want is going to be required by a large proportion of
>>>> developers. Say I am presented an InstrumentDomain object and need
>>>> to get its IssuerClass, my current only option seems to be to resort
>>>> to the native SQL and use the foreign key in the table underlying
>>>> InstrumentDomain to get it.
>>> I think a wire got cross somewhere. If you want any of your
>>> containment references to have an inverse (all elements referring to
>>> complex types will result in containment references), then you put an
>>> ecore:opposite on that element/element-ref and you give the name of
>>> the feature as it will appear in the reference's type. So say I have
>>> a class Parent that has an element "child" of type "Child", I would
>>> put ecore:opposite="parent" on that element declaration in the Parent
>>> complex type and as a result the Child EClass would end up with a
>>> "parent" feature of type "Parent"...
>> I am now confused. Reading this makes me think I should add to the
>> element definition in IssuerClass complexType definition.
> Yes, that's what I showed. It would have been more clear had I shown it
> in context:
>
> <xsd:complexType name="IssuerClass">
> <xsd:sequence>
> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
> maxOccurs="unbounded"
> ref="lib:instrumentDomain" />
> </xsd:sequence>
>
>> Terminology is a problem. So to clarify.
>> 1. In this case the containment reference in IssuerClass is:
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> ref="gensec:instrumentDomain" />
> Yes.
>> 2. The feature name is thus "gensec:issuerClass"?
> No, the feature name should just be a well formed Java identifier
> representing the actual name of the EMF feature you want generated.
>> (although "reference's type" suggests to me the far end of this
>> relationship)
> It will be a feature in the type of the element, i.e, InstrumentDomain.
>>
>> When I tried this as the reference
>> <xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
>> maxOccurs="unbounded" ref="gensec:instrumentDomain" />
>>
>> I got an error "The name "gensec:issuerClass" is not well formed"
> Remove the "gensec:", and you should be golden.
>>
>> Thx.
>>
>>
>>>>
>>>> David
>>>>
>>>> Ed Merks wrote:
>>>>> David,
>>>>>
>>>>> I think what you want is
>>>>>
>>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>>>>
>>>>>
>>>>> David Wynter wrote:
>>>>>> Martin,
>>>>>>
>>>>>> I added the suggested element and ended up with this:
>>>>>>
>>>>>> <xsd:complexType name="IssuerClass">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> ref="gensec:instrumentDomain" />
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>
>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>>>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>>>>> ref="gensec:instrumentDomain" />
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="instrumentDomain"
>>>>>> type="gensec:InstrumentDomain" />
>>>>>>
>>>>>> It still did not generate a InstrumentDomain.getIssuerClass() method.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> Is it possible (taking your model into account) to add a
>>>>>>> xsd:element in InstrumentDomain which points to IssuerClass
>>>>>>> (using an ecore:reference)? The ecore:opposite should be set in
>>>>>>> that xsd:element and it should be the name of the efeature in
>>>>>>> IssuerClass which has the instrumentdomains (in this case
>>>>>>> ecore:opposite="instrumentDomain" probably works).
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I added
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> ref="gensec:instrumentDomain"
>>>>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>>>>> ecore:opposite="issuerClass"/>
>>>>>>>>
>>>>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>>>>> method generated? I also tried without the ecore:reference but
>>>>>>>> got these weird errors "the opposite of the opposite many not be
>>>>>>>> a reference different from this one"
>>>>>>>>
>>>>>>>> I cannot use eContainer as the database schema has to be as
>>>>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>>>>> what i read.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>> Hi David,
>>>>>>>>> The eContainer() method should give you the parent in this
>>>>>>>>> case. You can also explicitly model the assocation back from
>>>>>>>>> the instrumentDomain to the IssuerClass, and set the eopposite,
>>>>>>>>> you can use the ecore:opposite attribute for that (see here
>>>>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> When you have a 0..* association the source code for the child
>>>>>>>>>> does not get generated with a convenience method to get the
>>>>>>>>>> parent. We have to go to the parent and use the getChild()
>>>>>>>>>> method then iterate through the EList returned looking for the
>>>>>>>>>> child we are dealing with. E.g.
>>>>>>>>>>
>>>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>>>> <xsd:sequence>
>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>>>> </xsd:sequence>
>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:attribute>
>>>>>>>>>> </xsd:complexType>
>>>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>>>
>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>> <xsd:sequence>
>>>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>>>> </xsd:sequence>
>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:attribute>
>>>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>>>> </xsd:complexType>
>>>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Will generate code with
>>>>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>>>>> find its IssuerClass, if it has one. This makes for very
>>>>>>>>>> awkward coding when you are passed a InstrumentDomain object.
>>>>>>>>>>
>>>>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>>>>> allow me to add this lookup of the parent in these one to many
>>>>>>>>>> associations, could not see it. Is there anything?
>>>>>>>>>>
>>>>>>>>>> Thx.
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422578 is a reply to message #422577] Tue, 09 September 2008 22:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040703010402060808030200
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

David,

Opposites must be pairs. I.e., the opposite of an opposite must be the
original feature. Thus, if you have multiple containment references to
the same type of object each such containment reference but specify an
opposite with a *different *name.


David Wynter wrote:
> Hi,
>
> I am golden, for a moment at least.
>
> I added this ecore:opposite to other elements in the same complexType.
> I am getting this error message.
>
> "The opposite of opposite may not be a reference different from this one"
>
> I checked for typos in the feature names. Am I allowed more than one
> of the referenced elements to have the same feature name?
>
> Thx.
>
> David
> "Ed Merks wrote:
>> David,
>>
>> Comments below.
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> Comments below. To clarify, IssuerClass is the parent and
>>> InstrumentDomain is the child.
>>>
>>> David
>>> Ed Merks wrote:
>>>> David,
>>>>
>>>> Comments below.
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> There seems to be some confusion,
>>>> You think?
>>>>> lets say you have a parent 0..* child. The standard xsd will
>>>>> generate a method for the parent to get all the children. I simply
>>>>> want a method that for a child it will fetch its only parent.
>>>> I gathered that...
>>>>>
>>>>> The element you suggested ended up adding the method with the
>>>>> right name but it returns objects not of the type of the parent,
>>>>> in this case IssuerClass,
>>>> In InstrumentDomain I get:
>>>>
>>>> IssuerClass getIssuerClass();
>>>>
>>>> The IssuerClass contains the InstrumentDomain and the
>>>> InstrumentDomain has a method for accessing that parent. I'm not
>>>> sure what I messed.
>>>>> but of the type of the child, in the case InstrumentDomain. So it
>>>>> appears to be a self referential relationship it set up.
>>>>>
>>>>> I changed it to this.
>>>>>
>>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>>> maxOccurs="1" ref="gensec:issuerClass" />
>>>> Just the names tell me this can't possibly be right...
>>>>>
>>>>> This does what I expect it to do in the InstrumentDomain class,
>>>>> adding IssuerClass InstrumentDomain.getIssuerCLass()
>>>> This you get even without the opposite, right?
>>> No I got this with exactly what I showed there. For clarity as here:
>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
>>> ref="gensec:issuerClass" />
>>> this is inside the InstrumentDomain complexType definition
>> Using ecore:opposite will not create a feature in the class
>> containing this element declaration. So your getIssuerClass method
>> is appearing because of the element declaration, not because of the
>> ecore:opposite annotation.
>>>>>
>>>>> but it adds a superflous method
>>>>> InstrumentDomain IssuerClass.getIssuerClass();
>>>> This is the part that's wrong because you aren't using opposite
>>>> appropriately.
>>> OK that is clear to me
>>>>>
>>>>> I already have EList<InstrumentDomain>
>>>>> IssuerClass.getInstrumentDomain()
>>>>>
>>>>> Which is the real one I need.
>>>>>
>>>>> What I want is going to be required by a large proportion of
>>>>> developers. Say I am presented an InstrumentDomain object and need
>>>>> to get its IssuerClass, my current only option seems to be to
>>>>> resort to the native SQL and use the foreign key in the table
>>>>> underlying InstrumentDomain to get it.
>>>> I think a wire got cross somewhere. If you want any of your
>>>> containment references to have an inverse (all elements referring
>>>> to complex types will result in containment references), then you
>>>> put an ecore:opposite on that element/element-ref and you give the
>>>> name of the feature as it will appear in the reference's type. So
>>>> say I have a class Parent that has an element "child" of type
>>>> "Child", I would put ecore:opposite="parent" on that element
>>>> declaration in the Parent complex type and as a result the Child
>>>> EClass would end up with a "parent" feature of type "Parent"...
>>> I am now confused. Reading this makes me think I should add to the
>>> element definition in IssuerClass complexType definition.
>> Yes, that's what I showed. It would have been more clear had I shown
>> it in context:
>>
>> <xsd:complexType name="IssuerClass">
>> <xsd:sequence>
>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>> maxOccurs="unbounded"
>> ref="lib:instrumentDomain" />
>> </xsd:sequence>
>>
>>> Terminology is a problem. So to clarify.
>>> 1. In this case the containment reference in IssuerClass is:
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> ref="gensec:instrumentDomain" />
>> Yes.
>>> 2. The feature name is thus "gensec:issuerClass"?
>> No, the feature name should just be a well formed Java identifier
>> representing the actual name of the EMF feature you want generated.
>>> (although "reference's type" suggests to me the far end of this
>>> relationship)
>> It will be a feature in the type of the element, i.e, InstrumentDomain.
>>>
>>> When I tried this as the reference
>>> <xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
>>> maxOccurs="unbounded" ref="gensec:instrumentDomain" />
>>>
>>> I got an error "The name "gensec:issuerClass" is not well formed"
>> Remove the "gensec:", and you should be golden.
>>>
>>> Thx.
>>>
>>>
>>>>>
>>>>> David
>>>>>
>>>>> Ed Merks wrote:
>>>>>> David,
>>>>>>
>>>>>> I think what you want is
>>>>>>
>>>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>>>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>>>>>
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Martin,
>>>>>>>
>>>>>>> I added the suggested element and ended up with this:
>>>>>>>
>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>
>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>>>>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>
>>>>>>> It still did not generate a InstrumentDomain.getIssuerClass()
>>>>>>> method.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> Is it possible (taking your model into account) to add a
>>>>>>>> xsd:element in InstrumentDomain which points to IssuerClass
>>>>>>>> (using an ecore:reference)? The ecore:opposite should be set in
>>>>>>>> that xsd:element and it should be the name of the efeature in
>>>>>>>> IssuerClass which has the instrumentdomains (in this case
>>>>>>>> ecore:opposite="instrumentDomain" probably works).
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I added
>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>> ref="gensec:instrumentDomain"
>>>>>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>>>>>> ecore:opposite="issuerClass"/>
>>>>>>>>>
>>>>>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>>>>>> method generated? I also tried without the ecore:reference but
>>>>>>>>> got these weird errors "the opposite of the opposite many not
>>>>>>>>> be a reference different from this one"
>>>>>>>>>
>>>>>>>>> I cannot use eContainer as the database schema has to be as
>>>>>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>>>>>> what i read.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>>
>>>>>>>>> Martin Taal wrote:
>>>>>>>>>> Hi David,
>>>>>>>>>> The eContainer() method should give you the parent in this
>>>>>>>>>> case. You can also explicitly model the assocation back from
>>>>>>>>>> the instrumentDomain to the IssuerClass, and set the
>>>>>>>>>> eopposite, you can use the ecore:opposite attribute for that
>>>>>>>>>> (see here
>>>>>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> gr. Martin
>>>>>>>>>>
>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> When you have a 0..* association the source code for the
>>>>>>>>>>> child does not get generated with a convenience method to
>>>>>>>>>>> get the parent. We have to go to the parent and use the
>>>>>>>>>>> getChild() method then iterate through the EList returned
>>>>>>>>>>> looking for the child we are dealing with. E.g.
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Will generate code with
>>>>>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>>>>>> find its IssuerClass, if it has one. This makes for very
>>>>>>>>>>> awkward coding when you are passed a InstrumentDomain object.
>>>>>>>>>>>
>>>>>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>>>>>> allow me to add this lookup of the parent in these one to
>>>>>>>>>>> many associations, could not see it. Is there anything?
>>>>>>>>>>>
>>>>>>>>>>> Thx.
>>>>>>>>>>>
>>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>>>>>>>

--------------040703010402060808030200
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">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
David,<br>
<br>
Opposites must be pairs.&nbsp; I.e., the opposite of an opposite must be the
original feature.&nbsp; Thus, if you have multiple containment references to
the same type of object each such containment reference but specify an
opposite with a <b>different </b>name.<br>
<br>
<br>
David Wynter wrote:
<blockquote cite="mid:ga6u8e$kvc$1@build.eclipse.org" type="cite">Hi,
<br>
<br>
I am golden, for a moment at least.
<br>
<br>
I added this ecore:opposite to other elements in the same complexType.
I am getting this error message.
<br>
<br>
"The opposite of opposite may not be a reference different from this
one"
<br>
<br>
I checked for typos in the feature names. Am I allowed more than one of
the referenced elements to have the same feature name?
<br>
<br>
Thx.
<br>
<br>
David
<br>
"Ed Merks wrote:
<br>
<blockquote type="cite">David,
<br>
<br>
Comments below.
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
Comments below. To clarify, IssuerClass is the parent and
InstrumentDomain is the child.
<br>
<br>
David
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">David,
<br>
<br>
Comments below.
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
There seems to be some confusion,
<br>
</blockquote>
You think?
<br>
<blockquote type="cite">lets say you have a parent 0..* child.
The standard xsd will generate a method for the parent to get all the
children. I simply want a method that for a child it will fetch its
only parent.
<br>
</blockquote>
I gathered that...
<br>
<blockquote type="cite"><br>
The element you suggested ended up adding the method with the right
name but it returns objects not of the type of the parent, in this case
IssuerClass, </blockquote>
In InstrumentDomain I get:
<br>
<br>
&nbsp;IssuerClass getIssuerClass();
<br>
<br>
The IssuerClass contains the InstrumentDomain and the InstrumentDomain
has a method for accessing that parent.&nbsp; I'm not sure what I messed.
<br>
<blockquote type="cite">but of the type of the child, in the
case InstrumentDomain.&nbsp; So it appears to be a self referential
relationship it set up.
<br>
<br>
I changed it to this.
<br>
<br>
&lt;xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="1" ref="gensec:issuerClass" /&gt;
<br>
</blockquote>
Just the names tell me this can't possibly be right...
<br>
<blockquote type="cite"><br>
This does what I expect it to do in the InstrumentDomain class, adding
IssuerClass InstrumentDomain.getIssuerCLass()
<br>
</blockquote>
This you get even without the opposite, right?
<br>
</blockquote>
No I got this with exactly what I showed there. For clarity as here:
<br>
&lt;xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="1"
<br>
&nbsp;ref="gensec:issuerClass" /&gt;
<br>
this is inside the InstrumentDomain complexType definition
<br>
</blockquote>
Using ecore:opposite will not create a feature in the class containing
this element declaration.&nbsp; So your getIssuerClass method is appearing
because of the element declaration, not because of the ecore:opposite
annotation.
<br>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite"><br>
but it adds a superflous method
<br>
InstrumentDomain IssuerClass.getIssuerClass();
<br>
</blockquote>
This is the part that's wrong because you aren't using opposite
appropriately.
<br>
</blockquote>
OK that is clear to me
<br>
<blockquote type="cite">
<blockquote type="cite"><br>
I already have EList&lt;InstrumentDomain&gt;
IssuerClass.getInstrumentDomain()
<br>
<br>
Which is the real one I need.
<br>
<br>
What I want is going to be required by a large proportion of
developers. Say I am presented an InstrumentDomain object and need to
get its IssuerClass, my current only option seems to be to resort to
the native SQL and use the foreign key in the table underlying
InstrumentDomain to get it.
<br>
</blockquote>
I think a wire got cross somewhere.&nbsp; If you want any of your
containment references to have an inverse (all elements referring to
complex types will result in containment references), then you put an
ecore:opposite on that element/element-ref and you give the name of the
feature as it will appear in the reference's type.&nbsp; So say I have a
class Parent that has an element "child" of type "Child", I would&nbsp; put
ecore:opposite="parent" on that element declaration in the Parent
complex type and as a result the Child EClass would end up with a
"parent" feature of type "Parent"...
<br>
</blockquote>
I am now confused. Reading this makes me think I should add to the
element definition in IssuerClass complexType definition. </blockquote>
Yes, that's what I showed.&nbsp; It would have been more clear had I shown
it in context:
<br>
<br>
&lt;xsd:complexType name="IssuerClass"&gt;
<br>
&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element ecore:opposite="issuerClass" minOccurs="0"
maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ref="lib:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
<br>
<blockquote type="cite">Terminology is a problem. So to clarify.
<br>
1. In this case the containment reference in IssuerClass is:
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
ref="gensec:instrumentDomain" /&gt;
<br>
</blockquote>
Yes.
<br>
<blockquote type="cite">2. The feature name is thus
"gensec:issuerClass"?
<br>
</blockquote>
No, the feature name should just be a well formed Java identifier
representing the actual name of the EMF feature you want generated.
<br>
<blockquote type="cite">(although "reference's type" suggests to me
the far end of this relationship)
<br>
</blockquote>
It will be a feature in the type of the element, i.e, InstrumentDomain.
<br>
<blockquote type="cite"><br>
When I tried this as the reference
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
maxOccurs="unbounded" ref="gensec:instrumentDomain" /&gt;
<br>
<br>
I got an error "The name "gensec:issuerClass" is not well formed"
<br>
</blockquote>
Remove the "gensec:", and you should be golden.
<br>
<blockquote type="cite"><br>
Thx.
<br>
<br>
<br>
<blockquote type="cite">
<blockquote type="cite"><br>
David
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">David,
<br>
<br>
I think what you want is
<br>
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:element ecore:opposite="issuerClass" minOccurs="0"
<br>
&nbsp;&nbsp;&nbsp; maxOccurs="unbounded" ref="lib:instrumentDomain" /&gt;
<br>
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite">Martin,
<br>
<br>
I added the suggested element and ended up with this:
<br>
<br>
&nbsp;&nbsp; &lt;xsd:complexType name="IssuerClass"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp;&nbsp; &lt;xsd:element name="issuerClass" type="gensec:IssuerClass" /&gt;
<br>
<br>
&nbsp;&nbsp; &lt;xsd:complexType name="InstrumentDomain"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element maxOccurs="unbounded"
<br>
&nbsp;ref="gensec:instrumentIdentifier" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element ecore:reference="gensec:IssuerClass"
ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="name" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="shortName" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp;&nbsp; &lt;xsd:element name="instrumentDomain"
<br>
&nbsp;type="gensec:InstrumentDomain" /&gt;
<br>
<br>
It still did not generate a InstrumentDomain.getIssuerClass() method.
<br>
<br>
Regards,
<br>
<br>
David
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Hi David,
<br>
Is it possible (taking your model into account) to add a xsd:element in
InstrumentDomain which points to IssuerClass (using an
ecore:reference)? The ecore:opposite should be set in that xsd:element
and it should be the name of the efeature in IssuerClass which has the
instrumentdomains (in this case ecore:opposite="instrumentDomain"
probably works).
<br>
<br>
gr. Martin
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite"><br>
Hi,
<br>
<br>
I added
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ref="gensec:instrumentDomain"
ecore:reference="gensec:InstrumentDomain"&nbsp;
ecore:opposite="issuerClass"/&gt;
<br>
<br>
But did not get the expected InstrumentDomain.getIssuerClass() method
generated? I also tried without the ecore:reference but got these weird
errors "the opposite of the opposite many not be a reference different
from this one"
<br>
<br>
I cannot use eContainer as the database schema has to be as unadorned
as is possible. Using eContainer adds 3 columns from what i read.
<br>
<br>
Regards,
<br>
<br>
David
<br>
<br>
Martin Taal wrote:
<br>
<blockquote type="cite">Hi David,
<br>
The eContainer() method should give you the parent in this case. You
can also explicitly model the assocation back from the instrumentDomain
to the IssuerClass, and set the eopposite, you can use the
ecore:opposite attribute for that (see here
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf"> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf</a>)
<br>
<br>
gr. Martin
<br>
<br>
David Wynter wrote:
<br>
<blockquote type="cite">Hi,
<br>
<br>
When you have a 0..* association the source code for the child does not
get generated with a convenience method to get the parent. We have to
go to the parent and use the getChild() method then iterate through the
EList returned looking for the child we are dealing with. E.g.
<br>
<br>
&nbsp; &lt;xsd:complexType name="IssuerClass"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:element minOccurs="0" maxOccurs="unbounded"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ref="gensec:instrumentDomain" /&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp; &lt;xsd:element name="issuerClass" type="gensec:IssuerClass" /&gt;
<br>
<br>
&nbsp; &lt;xsd:complexType name="InstrumentDomain"&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:element maxOccurs="unbounded"
ref="gensec:instrumentIdentifier" /&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/xsd:sequence&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="id" type="xsd:int"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xsd:appinfo source="teneo.jpa"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Id @GeneratedValue(strategy=IDENTITY)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xsd:appinfo&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsd:annotation&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;/xsd:attribute&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="name" type="xsd:string" /&gt;
<br>
&nbsp;&nbsp;&nbsp; &lt;xsd:attribute name="shortName" type="xsd:string" /&gt;
<br>
&nbsp; &lt;/xsd:complexType&gt;
<br>
&nbsp; &lt;xsd:element name="instrumentDomain"
type="gensec:InstrumentDomain" /&gt;
<br>
<br>
<br>
Will generate code with
<br>
&nbsp;&nbsp;&nbsp; EList&lt;InstrumentDomain&gt; getInstrumentDomain();
<br>
in IssuerClass. But nothing in the class InstrumentDomain to find its
IssuerClass, if it has one. This makes for very awkward coding when you
are passed a InstrumentDomain object.
<br>
<br>
I looked in the annotations to see if there was anything to allow me to
add this lookup of the parent in these one to many associations, could
not see it. Is there anything?
<br>
<br>
Thx.
<br>
<br>
David
<br>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>

--------------040703010402060808030200--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] 0..* associations, how to fetch parent from child [message #422579 is a reply to message #422578] Tue, 09 September 2008 23:10 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Thx, all working. Big model with 382 elements and about 100 opposites

David

Ed Merks wrote:
> David,
>
> Opposites must be pairs. I.e., the opposite of an opposite must be the
> original feature. Thus, if you have multiple containment references to
> the same type of object each such containment reference but specify an
> opposite with a *different *name.
>
>
> David Wynter wrote:
>> Hi,
>>
>> I am golden, for a moment at least.
>>
>> I added this ecore:opposite to other elements in the same complexType.
>> I am getting this error message.
>>
>> "The opposite of opposite may not be a reference different from this one"
>>
>> I checked for typos in the feature names. Am I allowed more than one
>> of the referenced elements to have the same feature name?
>>
>> Thx.
>>
>> David
>> "Ed Merks wrote:
>>> David,
>>>
>>> Comments below.
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> Comments below. To clarify, IssuerClass is the parent and
>>>> InstrumentDomain is the child.
>>>>
>>>> David
>>>> Ed Merks wrote:
>>>>> David,
>>>>>
>>>>> Comments below.
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> There seems to be some confusion,
>>>>> You think?
>>>>>> lets say you have a parent 0..* child. The standard xsd will
>>>>>> generate a method for the parent to get all the children. I simply
>>>>>> want a method that for a child it will fetch its only parent.
>>>>> I gathered that...
>>>>>>
>>>>>> The element you suggested ended up adding the method with the
>>>>>> right name but it returns objects not of the type of the parent,
>>>>>> in this case IssuerClass,
>>>>> In InstrumentDomain I get:
>>>>>
>>>>> IssuerClass getIssuerClass();
>>>>>
>>>>> The IssuerClass contains the InstrumentDomain and the
>>>>> InstrumentDomain has a method for accessing that parent. I'm not
>>>>> sure what I messed.
>>>>>> but of the type of the child, in the case InstrumentDomain. So it
>>>>>> appears to be a self referential relationship it set up.
>>>>>>
>>>>>> I changed it to this.
>>>>>>
>>>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>>>> maxOccurs="1" ref="gensec:issuerClass" />
>>>>> Just the names tell me this can't possibly be right...
>>>>>>
>>>>>> This does what I expect it to do in the InstrumentDomain class,
>>>>>> adding IssuerClass InstrumentDomain.getIssuerCLass()
>>>>> This you get even without the opposite, right?
>>>> No I got this with exactly what I showed there. For clarity as here:
>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0" maxOccurs="1"
>>>> ref="gensec:issuerClass" />
>>>> this is inside the InstrumentDomain complexType definition
>>> Using ecore:opposite will not create a feature in the class
>>> containing this element declaration. So your getIssuerClass method
>>> is appearing because of the element declaration, not because of the
>>> ecore:opposite annotation.
>>>>>>
>>>>>> but it adds a superflous method
>>>>>> InstrumentDomain IssuerClass.getIssuerClass();
>>>>> This is the part that's wrong because you aren't using opposite
>>>>> appropriately.
>>>> OK that is clear to me
>>>>>>
>>>>>> I already have EList<InstrumentDomain>
>>>>>> IssuerClass.getInstrumentDomain()
>>>>>>
>>>>>> Which is the real one I need.
>>>>>>
>>>>>> What I want is going to be required by a large proportion of
>>>>>> developers. Say I am presented an InstrumentDomain object and need
>>>>>> to get its IssuerClass, my current only option seems to be to
>>>>>> resort to the native SQL and use the foreign key in the table
>>>>>> underlying InstrumentDomain to get it.
>>>>> I think a wire got cross somewhere. If you want any of your
>>>>> containment references to have an inverse (all elements referring
>>>>> to complex types will result in containment references), then you
>>>>> put an ecore:opposite on that element/element-ref and you give the
>>>>> name of the feature as it will appear in the reference's type. So
>>>>> say I have a class Parent that has an element "child" of type
>>>>> "Child", I would put ecore:opposite="parent" on that element
>>>>> declaration in the Parent complex type and as a result the Child
>>>>> EClass would end up with a "parent" feature of type "Parent"...
>>>> I am now confused. Reading this makes me think I should add to the
>>>> element definition in IssuerClass complexType definition.
>>> Yes, that's what I showed. It would have been more clear had I shown
>>> it in context:
>>>
>>> <xsd:complexType name="IssuerClass">
>>> <xsd:sequence>
>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>> maxOccurs="unbounded"
>>> ref="lib:instrumentDomain" />
>>> </xsd:sequence>
>>>
>>>> Terminology is a problem. So to clarify.
>>>> 1. In this case the containment reference in IssuerClass is:
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> ref="gensec:instrumentDomain" />
>>> Yes.
>>>> 2. The feature name is thus "gensec:issuerClass"?
>>> No, the feature name should just be a well formed Java identifier
>>> representing the actual name of the EMF feature you want generated.
>>>> (although "reference's type" suggests to me the far end of this
>>>> relationship)
>>> It will be a feature in the type of the element, i.e, InstrumentDomain.
>>>>
>>>> When I tried this as the reference
>>>> <xsd:element ecore:opposite="gensec:issuerClass" minOccurs="0"
>>>> maxOccurs="unbounded" ref="gensec:instrumentDomain" />
>>>>
>>>> I got an error "The name "gensec:issuerClass" is not well formed"
>>> Remove the "gensec:", and you should be golden.
>>>>
>>>> Thx.
>>>>
>>>>
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> David,
>>>>>>>
>>>>>>> I think what you want is
>>>>>>>
>>>>>>> <xsd:element ecore:opposite="issuerClass" minOccurs="0"
>>>>>>> maxOccurs="unbounded" ref="lib:instrumentDomain" />
>>>>>>>
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Martin,
>>>>>>>>
>>>>>>>> I added the suggested element and ended up with this:
>>>>>>>>
>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>> <xsd:sequence>
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>> </xsd:sequence>
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> </xsd:complexType>
>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>
>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>> <xsd:sequence>
>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>> <xsd:element ecore:reference="gensec:IssuerClass"
>>>>>>>> ecore:opposite="instrumentDomain" minOccurs="0" maxOccurs="1"
>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>> </xsd:sequence>
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>> </xsd:complexType>
>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>
>>>>>>>> It still did not generate a InstrumentDomain.getIssuerClass()
>>>>>>>> method.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>> Hi David,
>>>>>>>>> Is it possible (taking your model into account) to add a
>>>>>>>>> xsd:element in InstrumentDomain which points to IssuerClass
>>>>>>>>> (using an ecore:reference)? The ecore:opposite should be set in
>>>>>>>>> that xsd:element and it should be the name of the efeature in
>>>>>>>>> IssuerClass which has the instrumentdomains (in this case
>>>>>>>>> ecore:opposite="instrumentDomain" probably works).
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I added
>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>> ref="gensec:instrumentDomain"
>>>>>>>>>> ecore:reference="gensec:InstrumentDomain"
>>>>>>>>>> ecore:opposite="issuerClass"/>
>>>>>>>>>>
>>>>>>>>>> But did not get the expected InstrumentDomain.getIssuerClass()
>>>>>>>>>> method generated? I also tried without the ecore:reference but
>>>>>>>>>> got these weird errors "the opposite of the opposite many not
>>>>>>>>>> be a reference different from this one"
>>>>>>>>>>
>>>>>>>>>> I cannot use eContainer as the database schema has to be as
>>>>>>>>>> unadorned as is possible. Using eContainer adds 3 columns from
>>>>>>>>>> what i read.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>> Martin Taal wrote:
>>>>>>>>>>> Hi David,
>>>>>>>>>>> The eContainer() method should give you the parent in this
>>>>>>>>>>> case. You can also explicitly model the assocation back from
>>>>>>>>>>> the instrumentDomain to the IssuerClass, and set the
>>>>>>>>>>> eopposite, you can use the ecore:opposite attribute for that
>>>>>>>>>>> (see here
>>>>>>>>>>> http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf)
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> gr. Martin
>>>>>>>>>>>
>>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> When you have a 0..* association the source code for the
>>>>>>>>>>>> child does not get generated with a convenience method to
>>>>>>>>>>>> get the parent. We have to go to the parent and use the
>>>>>>>>>>>> getChild() method then iterate through the EList returned
>>>>>>>>>>>> looking for the child we are dealing with. E.g.
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:complexType name="IssuerClass">
>>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>>> ref="gensec:instrumentDomain" />
>>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>> <xsd:element name="issuerClass" type="gensec:IssuerClass" />
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>>> <xsd:element maxOccurs="unbounded"
>>>>>>>>>>>> ref="gensec:instrumentIdentifier" />
>>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>>> <xsd:attribute name="name" type="xsd:string" />
>>>>>>>>>>>> <xsd:attribute name="shortName" type="xsd:string" />
>>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Will generate code with
>>>>>>>>>>>> EList<InstrumentDomain> getInstrumentDomain();
>>>>>>>>>>>> in IssuerClass. But nothing in the class InstrumentDomain to
>>>>>>>>>>>> find its IssuerClass, if it has one. This makes for very
>>>>>>>>>>>> awkward coding when you are passed a InstrumentDomain object.
>>>>>>>>>>>>
>>>>>>>>>>>> I looked in the annotations to see if there was anything to
>>>>>>>>>>>> allow me to add this lookup of the parent in these one to
>>>>>>>>>>>> many associations, could not see it. Is there anything?
>>>>>>>>>>>>
>>>>>>>>>>>> Thx.
>>>>>>>>>>>>
>>>>>>>>>>>> David
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
Previous Topic:Avoiding "Cannot modify resource set without a write transaction" in lazy initialization
Next Topic:[CDO] Transparent CDO integration into generated EMF editor
Goto Forum:
  


Current Time: Fri Apr 19 10:44:57 GMT 2024

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

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

Back to the top