Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Ignoring annotation defining @Column name =
[Teneo] Ignoring annotation defining @Column name = [message #424008] Tue, 14 October 2008 09:37 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I want a self referential 0..1 relationship. So have the element defined
like this

<xsd:complexType name="InstrumentDomain">
<xsd:sequence>
<xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
maxOccurs="1" name="underlyingInstrument" type="gensec:InstrumentDomain" >
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
</xsd:annotation>
</xsd:element>
.....
</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="instrumentDomain" type="gensec:InstrumentDomain" />


What I get is a column name INSTRUMENTDOMAIN as the foreign key, not
underlyinginstrument as I expected. Anything else I need to do to force
the name I need?

Thx.

David
Re: [Teneo] Ignoring annotation defining @Column name = [message #424012 is a reply to message #424008] Tue, 14 October 2008 10:10 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Does @JoinColumn work here? Also it is possible the name needs to be enclosed with "

gr. Martin

David Wynter wrote:
> Hi,
>
> I want a self referential 0..1 relationship. So have the element defined
> like this
>
> <xsd:complexType name="InstrumentDomain">
> <xsd:sequence>
> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
> maxOccurs="1" name="underlyingInstrument" type="gensec:InstrumentDomain" >
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
> </xsd:annotation>
> </xsd:element>
> .....
> </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="instrumentDomain" type="gensec:InstrumentDomain" />
>
>
> What I get is a column name INSTRUMENTDOMAIN as the foreign key, not
> underlyinginstrument as I expected. Anything else I need to do to force
> the name I need?
>
> 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] Ignoring annotation defining @Column name = [message #424015 is a reply to message #424012] Tue, 14 October 2008 11:10 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I tried both

<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@JoinColumn(name="underlyinginstrument")
</xsd:appinfo>
</xsd:annotation>


and
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Column(name="underlyinginstrument")
</xsd:appinfo>
</xsd:annotation>

Neither changed the column name generated. Each time I made sure I
dropped th etabl ein the schema, did "Reload..." on the .genmodel, then
"Generate Model Code", then ran my main class to do the datastore
initialize(). The table is recreated, but with INSTRUMENTDOMAIN as the
FK column name.

Regards,

David

Martin Taal wrote:
> Hi David,
> Does @JoinColumn work here? Also it is possible the name needs to be
> enclosed with "
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> I want a self referential 0..1 relationship. So have the element
>> defined like this
>>
>> <xsd:complexType name="InstrumentDomain">
>> <xsd:sequence>
>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>> maxOccurs="1" name="underlyingInstrument"
>> type="gensec:InstrumentDomain" >
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>> </xsd:annotation>
>> </xsd:element>
>> .....
>> </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="instrumentDomain" type="gensec:InstrumentDomain" />
>>
>>
>> What I get is a column name INSTRUMENTDOMAIN as the foreign key, not
>> underlyinginstrument as I expected. Anything else I need to do to
>> force the name I need?
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424016 is a reply to message #424015] Tue, 14 October 2008 11:19 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

This might be useful too, from, the generated hibernate.hbm.xml file for
this column

<one-to-one name="underlyingInstrument" entity-name="InstrumentDomain"
foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
lazy="false" property-ref="instrumentDomain"/>


David

David Wynter wrote:
> Hi,
>
> I tried both
>
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @JoinColumn(name="underlyinginstrument")
> </xsd:appinfo>
> </xsd:annotation>
>
>
> and
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Column(name="underlyinginstrument")
> </xsd:appinfo>
> </xsd:annotation>
>
> Neither changed the column name generated. Each time I made sure I
> dropped th etabl ein the schema, did "Reload..." on the .genmodel, then
> "Generate Model Code", then ran my main class to do the datastore
> initialize(). The table is recreated, but with INSTRUMENTDOMAIN as the
> FK column name.
>
> Regards,
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> Does @JoinColumn work here? Also it is possible the name needs to be
>> enclosed with "
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I want a self referential 0..1 relationship. So have the element
>>> defined like this
>>>
>>> <xsd:complexType name="InstrumentDomain">
>>> <xsd:sequence>
>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>> maxOccurs="1" name="underlyingInstrument"
>>> type="gensec:InstrumentDomain" >
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>> </xsd:annotation>
>>> </xsd:element>
>>> .....
>>> </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="instrumentDomain" type="gensec:InstrumentDomain" />
>>>
>>>
>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key, not
>>> underlyinginstrument as I expected. Anything else I need to do to
>>> force the name I need?
>>>
>>> Thx.
>>>
>>> David
>>
>>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424017 is a reply to message #424016] Tue, 14 October 2008 11:39 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
This issue seems familiar :-)

Hmm, afaics there are two sides:
InstrumentDomain.underlyingInstrument <--> InstrumentDomain.instrumentDomain

Teneo will generate a one-to-one on one side and the many-to-one on the other side (can you check?).
The foreign key field is controlled/set by the many-to-one. In this case Teneo chooses to place the
manytoone in InstrumentDomain.instrumentDomain. I think you can solve this by setting the @OneToOne
annotation in InstrumentDomain.instrumentDomain with mappedBy having the efeature name of the other
side.
Then keep the joincolum annotation in underlyinginstrument.

gr. Martin

David Wynter wrote:
> Hi,
>
> This might be useful too, from, the generated hibernate.hbm.xml file for
> this column
>
> <one-to-one name="underlyingInstrument"
> entity-name="InstrumentDomain"
> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
> lazy="false" property-ref="instrumentDomain"/>
>
>
> David
>
> David Wynter wrote:
>> Hi,
>>
>> I tried both
>>
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @JoinColumn(name="underlyinginstrument")
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>>
>> and
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Column(name="underlyinginstrument")
>> </xsd:appinfo>
>> </xsd:annotation>
>>
>> Neither changed the column name generated. Each time I made sure I
>> dropped th etabl ein the schema, did "Reload..." on the .genmodel,
>> then "Generate Model Code", then ran my main class to do the
>> datastore initialize(). The table is recreated, but with
>> INSTRUMENTDOMAIN as the FK column name.
>>
>> Regards,
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> Does @JoinColumn work here? Also it is possible the name needs to be
>>> enclosed with "
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> I want a self referential 0..1 relationship. So have the element
>>>> defined like this
>>>>
>>>> <xsd:complexType name="InstrumentDomain">
>>>> <xsd:sequence>
>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>> maxOccurs="1" name="underlyingInstrument"
>>>> type="gensec:InstrumentDomain" >
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> .....
>>>> </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="instrumentDomain"
>>>> type="gensec:InstrumentDomain" />
>>>>
>>>>
>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key, not
>>>> underlyinginstrument as I expected. Anything else I need to do to
>>>> force the name I need?
>>>>
>>>> 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] Ignoring annotation defining @Column name = [message #424021 is a reply to message #424017] Tue, 14 October 2008 15:05 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I saw the thread on @OneToOne from Roland Brand but find the switch from
ECore annotation to XSD annotation not straightforward.

I must be missing something still

I have

<xsd:complexType name="InstrumentDomain">
<xsd:sequence>
<xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
maxOccurs="1" name="underlyingInstrument" type="gensec:InstrumentDomain" >
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToOne
@JoinColumn(name="underlyinginstrument")
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
.....
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
@OneToOne(mappedBy="underlyingInstrument")
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
.....
</xsd:complexType>
<xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />


What I don't get is that this is self referential, and the only 'other
side' there is is the generated primary key for the element, a
attribute. So if attribute does not support @OneToOne then how do you
specify the 'other side'?

It gives me -
Exception in thread "main"
org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: The
eclass: HbAnnotatedEAttribute does not have an efeature for OneToOne
at
org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)


Thx.

David

Martin Taal wrote:
> Hi David,
> This issue seems familiar :-)
>
> Hmm, afaics there are two sides:
> InstrumentDomain.underlyingInstrument <-->
> InstrumentDomain.instrumentDomain
>
> Teneo will generate a one-to-one on one side and the many-to-one on the
> other side (can you check?). The foreign key field is controlled/set by
> the many-to-one. In this case Teneo chooses to place the manytoone in
> InstrumentDomain.instrumentDomain. I think you can solve this by setting
> the @OneToOne annotation in InstrumentDomain.instrumentDomain with
> mappedBy having the efeature name of the other side.
> Then keep the joincolum annotation in underlyinginstrument.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> This might be useful too, from, the generated hibernate.hbm.xml file
>> for this column
>>
>> <one-to-one name="underlyingInstrument"
>> entity-name="InstrumentDomain"
>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>> lazy="false" property-ref="instrumentDomain"/>
>>
>>
>> David
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I tried both
>>>
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @JoinColumn(name="underlyinginstrument")
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>>
>>> and
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Column(name="underlyinginstrument")
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>>
>>> Neither changed the column name generated. Each time I made sure I
>>> dropped th etabl ein the schema, did "Reload..." on the .genmodel,
>>> then "Generate Model Code", then ran my main class to do the
>>> datastore initialize(). The table is recreated, but with
>>> INSTRUMENTDOMAIN as the FK column name.
>>>
>>> Regards,
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Does @JoinColumn work here? Also it is possible the name needs to be
>>>> enclosed with "
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I want a self referential 0..1 relationship. So have the element
>>>>> defined like this
>>>>>
>>>>> <xsd:complexType name="InstrumentDomain">
>>>>> <xsd:sequence>
>>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>>> maxOccurs="1" name="underlyingInstrument"
>>>>> type="gensec:InstrumentDomain" >
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo
>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> .....
>>>>> </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="instrumentDomain"
>>>>> type="gensec:InstrumentDomain" />
>>>>>
>>>>>
>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key,
>>>>> not underlyinginstrument as I expected. Anything else I need to do
>>>>> to force the name I need?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>>
>
>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424022 is a reply to message #424021] Tue, 14 October 2008 15:12 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
I think the @OneToOne should be in the instrumentDomain element because that's the opposite of the
underlyingInstrument.

gr. Martin

David Wynter wrote:
> Hi,
>
> I saw the thread on @OneToOne from Roland Brand but find the switch from
> ECore annotation to XSD annotation not straightforward.
>
> I must be missing something still
>
> I have
>
> <xsd:complexType name="InstrumentDomain">
> <xsd:sequence>
> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
> maxOccurs="1" name="underlyingInstrument" type="gensec:InstrumentDomain" >
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @ManyToOne
> @JoinColumn(name="underlyinginstrument")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> .....
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> @OneToOne(mappedBy="underlyingInstrument")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> .....
> </xsd:complexType>
> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>
>
> What I don't get is that this is self referential, and the only 'other
> side' there is is the generated primary key for the element, a
> attribute. So if attribute does not support @OneToOne then how do you
> specify the 'other side'?
>
> It gives me -
> Exception in thread "main"
> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: The
> eclass: HbAnnotatedEAttribute does not have an efeature for OneToOne
> at
> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>
>
> Thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> This issue seems familiar :-)
>>
>> Hmm, afaics there are two sides:
>> InstrumentDomain.underlyingInstrument <-->
>> InstrumentDomain.instrumentDomain
>>
>> Teneo will generate a one-to-one on one side and the many-to-one on
>> the other side (can you check?). The foreign key field is
>> controlled/set by the many-to-one. In this case Teneo chooses to place
>> the manytoone in InstrumentDomain.instrumentDomain. I think you can
>> solve this by setting the @OneToOne annotation in
>> InstrumentDomain.instrumentDomain with mappedBy having the efeature
>> name of the other side.
>> Then keep the joincolum annotation in underlyinginstrument.
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> This might be useful too, from, the generated hibernate.hbm.xml file
>>> for this column
>>>
>>> <one-to-one name="underlyingInstrument"
>>> entity-name="InstrumentDomain"
>>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>>> lazy="false" property-ref="instrumentDomain"/>
>>>
>>>
>>> David
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> I tried both
>>>>
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @JoinColumn(name="underlyinginstrument")
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>>
>>>> and
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Column(name="underlyinginstrument")
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>>
>>>> Neither changed the column name generated. Each time I made sure I
>>>> dropped th etabl ein the schema, did "Reload..." on the .genmodel,
>>>> then "Generate Model Code", then ran my main class to do the
>>>> datastore initialize(). The table is recreated, but with
>>>> INSTRUMENTDOMAIN as the FK column name.
>>>>
>>>> Regards,
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> Does @JoinColumn work here? Also it is possible the name needs to
>>>>> be enclosed with "
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I want a self referential 0..1 relationship. So have the element
>>>>>> defined like this
>>>>>>
>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>>>> maxOccurs="1" name="underlyingInstrument"
>>>>>> type="gensec:InstrumentDomain" >
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo
>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>> .....
>>>>>> </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="instrumentDomain"
>>>>>> type="gensec:InstrumentDomain" />
>>>>>>
>>>>>>
>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key,
>>>>>> not underlyinginstrument as I expected. Anything else I need to do
>>>>>> to force the name I need?
>>>>>>
>>>>>> 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] Ignoring annotation defining @Column name = [message #424024 is a reply to message #424022] Tue, 14 October 2008 15:28 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

It is in InstrumentDomain. When I said that it is 'self referential', I
mean that InstrumentDomain has a relationship with itself. In other
words I want a InstrumentDomain to have a reference to a parent
InstrumentDomain. InstrumentDomain.id -<
InstrumentDomain.underlyingInstrument

Is that possible?

David

Martin Taal wrote:
> Hi David,
> I think the @OneToOne should be in the instrumentDomain element because
> that's the opposite of the underlyingInstrument.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> I saw the thread on @OneToOne from Roland Brand but find the switch
>> from ECore annotation to XSD annotation not straightforward.
>>
>> I must be missing something still
>>
>> I have
>>
>> <xsd:complexType name="InstrumentDomain">
>> <xsd:sequence>
>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>> maxOccurs="1" name="underlyingInstrument"
>> type="gensec:InstrumentDomain" >
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @ManyToOne
>> @JoinColumn(name="underlyinginstrument")
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> .....
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> @OneToOne(mappedBy="underlyingInstrument")
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> .....
>> </xsd:complexType>
>> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>>
>>
>> What I don't get is that this is self referential, and the only 'other
>> side' there is is the generated primary key for the element, a
>> attribute. So if attribute does not support @OneToOne then how do you
>> specify the 'other side'?
>>
>> It gives me -
>> Exception in thread "main"
>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>> The eclass: HbAnnotatedEAttribute does not have an efeature for OneToOne
>> at
>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>
>>
>> Thx.
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> This issue seems familiar :-)
>>>
>>> Hmm, afaics there are two sides:
>>> InstrumentDomain.underlyingInstrument <-->
>>> InstrumentDomain.instrumentDomain
>>>
>>> Teneo will generate a one-to-one on one side and the many-to-one on
>>> the other side (can you check?). The foreign key field is
>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>> place the manytoone in InstrumentDomain.instrumentDomain. I think you
>>> can solve this by setting the @OneToOne annotation in
>>> InstrumentDomain.instrumentDomain with mappedBy having the efeature
>>> name of the other side.
>>> Then keep the joincolum annotation in underlyinginstrument.
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> This might be useful too, from, the generated hibernate.hbm.xml file
>>>> for this column
>>>>
>>>> <one-to-one name="underlyingInstrument"
>>>> entity-name="InstrumentDomain"
>>>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>>>> lazy="false" property-ref="instrumentDomain"/>
>>>>
>>>>
>>>> David
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I tried both
>>>>>
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @JoinColumn(name="underlyinginstrument")
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>>
>>>>> and
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Column(name="underlyinginstrument")
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>>
>>>>> Neither changed the column name generated. Each time I made sure I
>>>>> dropped th etabl ein the schema, did "Reload..." on the .genmodel,
>>>>> then "Generate Model Code", then ran my main class to do the
>>>>> datastore initialize(). The table is recreated, but with
>>>>> INSTRUMENTDOMAIN as the FK column name.
>>>>>
>>>>> Regards,
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> Does @JoinColumn work here? Also it is possible the name needs to
>>>>>> be enclosed with "
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I want a self referential 0..1 relationship. So have the element
>>>>>>> defined like this
>>>>>>>
>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo
>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>> .....
>>>>>>> </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="instrumentDomain"
>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>
>>>>>>>
>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key,
>>>>>>> not underlyinginstrument as I expected. Anything else I need to
>>>>>>> do to force the name I need?
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>
>>>>>>
>>>
>>>
>
>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424026 is a reply to message #424024] Tue, 14 October 2008 15:41 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
For a unidirectional relation it is enough to have a instrumentdomain in the child which points to
the parent (like what you mention in your last post). This is a many-to-one. To get this just remove
the underlyinginstrument element.

In the model you showed two posts back you have a bidirectional relation (with maxOccurs="1" on both
sides) making it a one-to-one. This one-to-one can be modelled with one foreign key column on one of
the sides of the association.
So as far as I can see adding the @OneToOne to the instrumentDomain element would do the trick,
forcing the column to be handled by the underlyingInstrument.

gr. Martin

David Wynter wrote:
> Hi,
>
> It is in InstrumentDomain. When I said that it is 'self referential', I
> mean that InstrumentDomain has a relationship with itself. In other
> words I want a InstrumentDomain to have a reference to a parent
> InstrumentDomain. InstrumentDomain.id -<
> InstrumentDomain.underlyingInstrument
>
> Is that possible?
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> I think the @OneToOne should be in the instrumentDomain element
>> because that's the opposite of the underlyingInstrument.
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I saw the thread on @OneToOne from Roland Brand but find the switch
>>> from ECore annotation to XSD annotation not straightforward.
>>>
>>> I must be missing something still
>>>
>>> I have
>>>
>>> <xsd:complexType name="InstrumentDomain">
>>> <xsd:sequence>
>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>> maxOccurs="1" name="underlyingInstrument"
>>> type="gensec:InstrumentDomain" >
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @ManyToOne
>>> @JoinColumn(name="underlyinginstrument")
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> .....
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> @OneToOne(mappedBy="underlyingInstrument")
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> .....
>>> </xsd:complexType>
>>> <xsd:element name="instrumentDomain" type="gensec:InstrumentDomain" />
>>>
>>>
>>> What I don't get is that this is self referential, and the only
>>> 'other side' there is is the generated primary key for the element, a
>>> attribute. So if attribute does not support @OneToOne then how do you
>>> specify the 'other side'?
>>>
>>> It gives me -
>>> Exception in thread "main"
>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>> The eclass: HbAnnotatedEAttribute does not have an efeature for OneToOne
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>>
>>>
>>> Thx.
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> This issue seems familiar :-)
>>>>
>>>> Hmm, afaics there are two sides:
>>>> InstrumentDomain.underlyingInstrument <-->
>>>> InstrumentDomain.instrumentDomain
>>>>
>>>> Teneo will generate a one-to-one on one side and the many-to-one on
>>>> the other side (can you check?). The foreign key field is
>>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>>> place the manytoone in InstrumentDomain.instrumentDomain. I think
>>>> you can solve this by setting the @OneToOne annotation in
>>>> InstrumentDomain.instrumentDomain with mappedBy having the efeature
>>>> name of the other side.
>>>> Then keep the joincolum annotation in underlyinginstrument.
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> This might be useful too, from, the generated hibernate.hbm.xml
>>>>> file for this column
>>>>>
>>>>> <one-to-one name="underlyingInstrument"
>>>>> entity-name="InstrumentDomain"
>>>>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>>>>> lazy="false" property-ref="instrumentDomain"/>
>>>>>
>>>>>
>>>>> David
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I tried both
>>>>>>
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>>
>>>>>>
>>>>>> and
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Column(name="underlyinginstrument")
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>>
>>>>>> Neither changed the column name generated. Each time I made sure I
>>>>>> dropped th etabl ein the schema, did "Reload..." on the .genmodel,
>>>>>> then "Generate Model Code", then ran my main class to do the
>>>>>> datastore initialize(). The table is recreated, but with
>>>>>> INSTRUMENTDOMAIN as the FK column name.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> Does @JoinColumn work here? Also it is possible the name needs to
>>>>>>> be enclosed with "
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I want a self referential 0..1 relationship. So have the element
>>>>>>>> defined like this
>>>>>>>>
>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>> <xsd:sequence>
>>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo
>>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:element>
>>>>>>>> .....
>>>>>>>> </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="instrumentDomain"
>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>
>>>>>>>>
>>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign key,
>>>>>>>> not underlyinginstrument as I expected. Anything else I need to
>>>>>>>> do to force the name I need?
>>>>>>>>
>>>>>>>> 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] Ignoring annotation defining @Column name = [message #424028 is a reply to message #424026] Tue, 14 October 2008 16:27 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I thought there was too much annotation to produce something so simple.
I made the mistake of starting out from the many side and looking at it
as a one to one, i.e. I have only one parent from this end.

So I removed the underlyinginstrument element as suggested, which left
me with this

<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @GeneratedValue(strategy=IDENTITY)
@OneToOne(mappedBy="underlyingInstrument")
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
.....

This does not make sense as there is no underlyingInstrument anymore. So
I removed the @OneTone annotation.

So I used a simple element to generate the foreign key

<xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
maxOccurs="unbounded" name="underlyingInstrument"
type="gensec:InstrumentDomain" >
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Column(name="underlyinginstrument")</xsd:appinfo>
</xsd:annotation>
</xsd:element>

This worked as expected, but it did ignore my request for a column named
underlyinginstrument and instead created one called instrumentdomain. I
tried @JoinColumn instead but that created a separate column with that
name and left the instrumentdomain column in place, obviously not a
valid annotation combination.

If I can get it to name the column as I want it then I am there.

David

Martin Taal wrote:
> Hi David,
> For a unidirectional relation it is enough to have a instrumentdomain in
> the child which points to the parent (like what you mention in your last
> post). This is a many-to-one. To get this just remove the
> underlyinginstrument element.
>
> In the model you showed two posts back you have a bidirectional relation
> (with maxOccurs="1" on both sides) making it a one-to-one. This
> one-to-one can be modelled with one foreign key column on one of the
> sides of the association.
> So as far as I can see adding the @OneToOne to the instrumentDomain
> element would do the trick, forcing the column to be handled by the
> underlyingInstrument.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> It is in InstrumentDomain. When I said that it is 'self referential',
>> I mean that InstrumentDomain has a relationship with itself. In other
>> words I want a InstrumentDomain to have a reference to a parent
>> InstrumentDomain. InstrumentDomain.id -<
>> InstrumentDomain.underlyingInstrument
>>
>> Is that possible?
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> I think the @OneToOne should be in the instrumentDomain element
>>> because that's the opposite of the underlyingInstrument.
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> I saw the thread on @OneToOne from Roland Brand but find the switch
>>>> from ECore annotation to XSD annotation not straightforward.
>>>>
>>>> I must be missing something still
>>>>
>>>> I have
>>>>
>>>> <xsd:complexType name="InstrumentDomain">
>>>> <xsd:sequence>
>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>> maxOccurs="1" name="underlyingInstrument"
>>>> type="gensec:InstrumentDomain" >
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @ManyToOne
>>>> @JoinColumn(name="underlyinginstrument")
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> .....
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>> @OneToOne(mappedBy="underlyingInstrument")
>>>> </xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> .....
>>>> </xsd:complexType>
>>>> <xsd:element name="instrumentDomain"
>>>> type="gensec:InstrumentDomain" />
>>>>
>>>>
>>>> What I don't get is that this is self referential, and the only
>>>> 'other side' there is is the generated primary key for the element,
>>>> a attribute. So if attribute does not support @OneToOne then how do
>>>> you specify the 'other side'?
>>>>
>>>> It gives me -
>>>> Exception in thread "main"
>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>> The eclass: HbAnnotatedEAttribute does not have an efeature for
>>>> OneToOne
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>>>
>>>>
>>>> Thx.
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> This issue seems familiar :-)
>>>>>
>>>>> Hmm, afaics there are two sides:
>>>>> InstrumentDomain.underlyingInstrument <-->
>>>>> InstrumentDomain.instrumentDomain
>>>>>
>>>>> Teneo will generate a one-to-one on one side and the many-to-one on
>>>>> the other side (can you check?). The foreign key field is
>>>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>>>> place the manytoone in InstrumentDomain.instrumentDomain. I think
>>>>> you can solve this by setting the @OneToOne annotation in
>>>>> InstrumentDomain.instrumentDomain with mappedBy having the efeature
>>>>> name of the other side.
>>>>> Then keep the joincolum annotation in underlyinginstrument.
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> This might be useful too, from, the generated hibernate.hbm.xml
>>>>>> file for this column
>>>>>>
>>>>>> <one-to-one name="underlyingInstrument"
>>>>>> entity-name="InstrumentDomain"
>>>>>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>>>>>> lazy="false" property-ref="instrumentDomain"/>
>>>>>>
>>>>>>
>>>>>> David
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I tried both
>>>>>>>
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>>
>>>>>>>
>>>>>>> and
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Column(name="underlyinginstrument")
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>>
>>>>>>> Neither changed the column name generated. Each time I made sure
>>>>>>> I dropped th etabl ein the schema, did "Reload..." on the
>>>>>>> .genmodel, then "Generate Model Code", then ran my main class to
>>>>>>> do the datastore initialize(). The table is recreated, but with
>>>>>>> INSTRUMENTDOMAIN as the FK column name.
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> Does @JoinColumn work here? Also it is possible the name needs
>>>>>>>> to be enclosed with "
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I want a self referential 0..1 relationship. So have the
>>>>>>>>> element defined like this
>>>>>>>>>
>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>> <xsd:sequence>
>>>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>>>>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>> .....
>>>>>>>>> </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="instrumentDomain"
>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign
>>>>>>>>> key, not underlyinginstrument as I expected. Anything else I
>>>>>>>>> need to do to force the name I need?
>>>>>>>>>
>>>>>>>>> Thx.
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>
>>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424029 is a reply to message #424028] Tue, 14 October 2008 16:51 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Just to be sure, a few posts back I mentioned to add this annotation:
@OneToOne(mappedBy="underlyingInstrument")

to the instrumentDomain element. Did you try this?
If not can you try and let me know what happens.

gr. Martin

David Wynter wrote:
> Hi,
>
> I thought there was too much annotation to produce something so simple.
> I made the mistake of starting out from the many side and looking at it
> as a one to one, i.e. I have only one parent from this end.
>
> So I removed the underlyinginstrument element as suggested, which left
> me with this
>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @GeneratedValue(strategy=IDENTITY)
> @OneToOne(mappedBy="underlyingInstrument")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> .....
>
> This does not make sense as there is no underlyingInstrument anymore. So
> I removed the @OneTone annotation.
>
> So I used a simple element to generate the foreign key
>
> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
> maxOccurs="unbounded" name="underlyingInstrument"
> type="gensec:InstrumentDomain" >
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Column(name="underlyinginstrument")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> This worked as expected, but it did ignore my request for a column named
> underlyinginstrument and instead created one called instrumentdomain. I
> tried @JoinColumn instead but that created a separate column with that
> name and left the instrumentdomain column in place, obviously not a
> valid annotation combination.
>
> If I can get it to name the column as I want it then I am there.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> For a unidirectional relation it is enough to have a instrumentdomain
>> in the child which points to the parent (like what you mention in your
>> last post). This is a many-to-one. To get this just remove the
>> underlyinginstrument element.
>>
>> In the model you showed two posts back you have a bidirectional
>> relation (with maxOccurs="1" on both sides) making it a one-to-one.
>> This one-to-one can be modelled with one foreign key column on one of
>> the sides of the association.
>> So as far as I can see adding the @OneToOne to the instrumentDomain
>> element would do the trick, forcing the column to be handled by the
>> underlyingInstrument.
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> It is in InstrumentDomain. When I said that it is 'self referential',
>>> I mean that InstrumentDomain has a relationship with itself. In other
>>> words I want a InstrumentDomain to have a reference to a parent
>>> InstrumentDomain. InstrumentDomain.id -<
>>> InstrumentDomain.underlyingInstrument
>>>
>>> Is that possible?
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> I think the @OneToOne should be in the instrumentDomain element
>>>> because that's the opposite of the underlyingInstrument.
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I saw the thread on @OneToOne from Roland Brand but find the switch
>>>>> from ECore annotation to XSD annotation not straightforward.
>>>>>
>>>>> I must be missing something still
>>>>>
>>>>> I have
>>>>>
>>>>> <xsd:complexType name="InstrumentDomain">
>>>>> <xsd:sequence>
>>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>>> maxOccurs="1" name="underlyingInstrument"
>>>>> type="gensec:InstrumentDomain" >
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @ManyToOne
>>>>> @JoinColumn(name="underlyinginstrument")
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> .....
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>> @OneToOne(mappedBy="underlyingInstrument")
>>>>> </xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> .....
>>>>> </xsd:complexType>
>>>>> <xsd:element name="instrumentDomain"
>>>>> type="gensec:InstrumentDomain" />
>>>>>
>>>>>
>>>>> What I don't get is that this is self referential, and the only
>>>>> 'other side' there is is the generated primary key for the element,
>>>>> a attribute. So if attribute does not support @OneToOne then how do
>>>>> you specify the 'other side'?
>>>>>
>>>>> It gives me -
>>>>> Exception in thread "main"
>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>> The eclass: HbAnnotatedEAttribute does not have an efeature for
>>>>> OneToOne
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>>>>
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> This issue seems familiar :-)
>>>>>>
>>>>>> Hmm, afaics there are two sides:
>>>>>> InstrumentDomain.underlyingInstrument <-->
>>>>>> InstrumentDomain.instrumentDomain
>>>>>>
>>>>>> Teneo will generate a one-to-one on one side and the many-to-one
>>>>>> on the other side (can you check?). The foreign key field is
>>>>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>>>>> place the manytoone in InstrumentDomain.instrumentDomain. I think
>>>>>> you can solve this by setting the @OneToOne annotation in
>>>>>> InstrumentDomain.instrumentDomain with mappedBy having the
>>>>>> efeature name of the other side.
>>>>>> Then keep the joincolum annotation in underlyinginstrument.
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> This might be useful too, from, the generated hibernate.hbm.xml
>>>>>>> file for this column
>>>>>>>
>>>>>>> <one-to-one name="underlyingInstrument"
>>>>>>> entity-name="InstrumentDomain"
>>>>>>> foreign-key="instrumentdomain_underlyinginstrument" cascade="all"
>>>>>>> lazy="false" property-ref="instrumentDomain"/>
>>>>>>>
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I tried both
>>>>>>>>
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>>
>>>>>>>>
>>>>>>>> and
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @Column(name="underlyinginstrument")
>>>>>>>> </xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>>
>>>>>>>> Neither changed the column name generated. Each time I made sure
>>>>>>>> I dropped th etabl ein the schema, did "Reload..." on the
>>>>>>>> .genmodel, then "Generate Model Code", then ran my main class to
>>>>>>>> do the datastore initialize(). The table is recreated, but with
>>>>>>>> INSTRUMENTDOMAIN as the FK column name.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>> Hi David,
>>>>>>>>> Does @JoinColumn work here? Also it is possible the name needs
>>>>>>>>> to be enclosed with "
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I want a self referential 0..1 relationship. So have the
>>>>>>>>>> element defined like this
>>>>>>>>>>
>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>> <xsd:sequence>
>>>>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo
>>>>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>>>>>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:element>
>>>>>>>>>> .....
>>>>>>>>>> </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="instrumentDomain"
>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign
>>>>>>>>>> key, not underlyinginstrument as I expected. Anything else I
>>>>>>>>>> need to do to force the name I need?
>>>>>>>>>>
>>>>>>>>>> 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] Ignoring annotation defining @Column name = [message #424045 is a reply to message #424029] Wed, 15 October 2008 08:58 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I cannot see where I can add that annotation. I have a complexType
called InstrumentDomain, also an element that called instrumentDomain
that uses that type. Inside that complexType, InstrumentDomain, I have

<xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
maxOccurs="unbounded" name="underlyingInstrument"
type="gensec:InstrumentDomain" >
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Column(name="underlyinginstrument")</xsd:appinfo>
</xsd:annotation>
</xsd:element>

I also have the primary key for that complexType, InstrumentDomain, as
an attribute, but I cannot add the @OneToOne annotation to that, as it
is not supported.

Do I create a new element called instrumentDomain inside that
complexType, InstrumentDomain, and add the annotation to that? It seems
to me that would create another column, which is not needed. If so, we
do not need to do this for 0..n where the many side element is a
different element to that on the one side. I.e. why a different approach
for self referential associations?

Just to rephrase this, there is only one type here, InstrumentDomain,
which has a one to many relationship with itself.

At this stage I have just changed my code to use the currently generated
column name, INSTRUMENTDOMAIN, at risk of making the database schema
less understandable.

thx.

David

Martin Taal wrote:
> Hi David,
> Just to be sure, a few posts back I mentioned to add this annotation:
> @OneToOne(mappedBy="underlyingInstrument")
>
> to the instrumentDomain element. Did you try this?
> If not can you try and let me know what happens.
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> I thought there was too much annotation to produce something so
>> simple. I made the mistake of starting out from the many side and
>> looking at it as a one to one, i.e. I have only one parent from this
>> end.
>>
>> So I removed the underlyinginstrument element as suggested, which left
>> me with this
>>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Id @GeneratedValue(strategy=IDENTITY)
>> @OneToOne(mappedBy="underlyingInstrument")
>> </xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> .....
>>
>> This does not make sense as there is no underlyingInstrument anymore.
>> So I removed the @OneTone annotation.
>>
>> So I used a simple element to generate the foreign key
>>
>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>> maxOccurs="unbounded" name="underlyingInstrument"
>> type="gensec:InstrumentDomain" >
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">
>> @Column(name="underlyinginstrument")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> This worked as expected, but it did ignore my request for a column
>> named underlyinginstrument and instead created one called
>> instrumentdomain. I tried @JoinColumn instead but that created a
>> separate column with that name and left the instrumentdomain column in
>> place, obviously not a valid annotation combination.
>>
>> If I can get it to name the column as I want it then I am there.
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> For a unidirectional relation it is enough to have a instrumentdomain
>>> in the child which points to the parent (like what you mention in
>>> your last post). This is a many-to-one. To get this just remove the
>>> underlyinginstrument element.
>>>
>>> In the model you showed two posts back you have a bidirectional
>>> relation (with maxOccurs="1" on both sides) making it a one-to-one.
>>> This one-to-one can be modelled with one foreign key column on one of
>>> the sides of the association.
>>> So as far as I can see adding the @OneToOne to the instrumentDomain
>>> element would do the trick, forcing the column to be handled by the
>>> underlyingInstrument.
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> It is in InstrumentDomain. When I said that it is 'self
>>>> referential', I mean that InstrumentDomain has a relationship with
>>>> itself. In other words I want a InstrumentDomain to have a reference
>>>> to a parent InstrumentDomain. InstrumentDomain.id -<
>>>> InstrumentDomain.underlyingInstrument
>>>>
>>>> Is that possible?
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> I think the @OneToOne should be in the instrumentDomain element
>>>>> because that's the opposite of the underlyingInstrument.
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I saw the thread on @OneToOne from Roland Brand but find the
>>>>>> switch from ECore annotation to XSD annotation not straightforward.
>>>>>>
>>>>>> I must be missing something still
>>>>>>
>>>>>> I have
>>>>>>
>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>> <xsd:sequence>
>>>>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>>>>> maxOccurs="1" name="underlyingInstrument"
>>>>>> type="gensec:InstrumentDomain" >
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToOne
>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>> .....
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>> @OneToOne(mappedBy="underlyingInstrument")
>>>>>> </xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> .....
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="instrumentDomain"
>>>>>> type="gensec:InstrumentDomain" />
>>>>>>
>>>>>>
>>>>>> What I don't get is that this is self referential, and the only
>>>>>> 'other side' there is is the generated primary key for the
>>>>>> element, a attribute. So if attribute does not support @OneToOne
>>>>>> then how do you specify the 'other side'?
>>>>>>
>>>>>> It gives me -
>>>>>> Exception in thread "main"
>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>> The eclass: HbAnnotatedEAttribute does not have an efeature for
>>>>>> OneToOne
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>>>>>
>>>>>>
>>>>>> Thx.
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> This issue seems familiar :-)
>>>>>>>
>>>>>>> Hmm, afaics there are two sides:
>>>>>>> InstrumentDomain.underlyingInstrument <-->
>>>>>>> InstrumentDomain.instrumentDomain
>>>>>>>
>>>>>>> Teneo will generate a one-to-one on one side and the many-to-one
>>>>>>> on the other side (can you check?). The foreign key field is
>>>>>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>>>>>> place the manytoone in InstrumentDomain.instrumentDomain. I think
>>>>>>> you can solve this by setting the @OneToOne annotation in
>>>>>>> InstrumentDomain.instrumentDomain with mappedBy having the
>>>>>>> efeature name of the other side.
>>>>>>> Then keep the joincolum annotation in underlyinginstrument.
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> This might be useful too, from, the generated hibernate.hbm.xml
>>>>>>>> file for this column
>>>>>>>>
>>>>>>>> <one-to-one name="underlyingInstrument"
>>>>>>>> entity-name="InstrumentDomain"
>>>>>>>> foreign-key="instrumentdomain_underlyinginstrument"
>>>>>>>> cascade="all" lazy="false" property-ref="instrumentDomain"/>
>>>>>>>>
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I tried both
>>>>>>>>>
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>>>>> </xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> and
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>> @Column(name="underlyinginstrument")
>>>>>>>>> </xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>>
>>>>>>>>> Neither changed the column name generated. Each time I made
>>>>>>>>> sure I dropped th etabl ein the schema, did "Reload..." on the
>>>>>>>>> .genmodel, then "Generate Model Code", then ran my main class
>>>>>>>>> to do the datastore initialize(). The table is recreated, but
>>>>>>>>> with INSTRUMENTDOMAIN as the FK column name.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>>
>>>>>>>>> Martin Taal wrote:
>>>>>>>>>> Hi David,
>>>>>>>>>> Does @JoinColumn work here? Also it is possible the name needs
>>>>>>>>>> to be enclosed with "
>>>>>>>>>>
>>>>>>>>>> gr. Martin
>>>>>>>>>>
>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I want a self referential 0..1 relationship. So have the
>>>>>>>>>>> element defined like this
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>>>>>>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>> .....
>>>>>>>>>>> </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="instrumentDomain"
>>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign
>>>>>>>>>>> key, not underlyinginstrument as I expected. Anything else I
>>>>>>>>>>> need to do to force the name I need?
>>>>>>>>>>>
>>>>>>>>>>> Thx.
>>>>>>>>>>>
>>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
Re: [Teneo] Ignoring annotation defining @Column name = [message #424047 is a reply to message #424045] Wed, 15 October 2008 09:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Probably in ecore there is an efeature called instrumentDomain within the InstrumentDomain EClass.
This is one is probably automatically created when you import the xsd into the emf genmodel. Teneo
uses the ecore and not the xsd. Therefore for Teneo there is an efeature instrumentdomain for which
it creates a join column.

To also have the same thing in xsd (==the instrumentdomain, to attach the annotation to) you indeed
need to add an element instrumentDomain which as an ecore:opposite of underlyingInstrument.
This element then has the onetoone annotation, which should only create one column in the
underlyinginstrument side.

gr. Martin

David Wynter wrote:
> Hi,
>
> I cannot see where I can add that annotation. I have a complexType
> called InstrumentDomain, also an element that called instrumentDomain
> that uses that type. Inside that complexType, InstrumentDomain, I have
>
> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
> maxOccurs="unbounded" name="underlyingInstrument"
> type="gensec:InstrumentDomain" >
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Column(name="underlyinginstrument")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> I also have the primary key for that complexType, InstrumentDomain, as
> an attribute, but I cannot add the @OneToOne annotation to that, as it
> is not supported.
>
> Do I create a new element called instrumentDomain inside that
> complexType, InstrumentDomain, and add the annotation to that? It seems
> to me that would create another column, which is not needed. If so, we
> do not need to do this for 0..n where the many side element is a
> different element to that on the one side. I.e. why a different approach
> for self referential associations?
>
> Just to rephrase this, there is only one type here, InstrumentDomain,
> which has a one to many relationship with itself.
>
> At this stage I have just changed my code to use the currently generated
> column name, INSTRUMENTDOMAIN, at risk of making the database schema
> less understandable.
>
> thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> Just to be sure, a few posts back I mentioned to add this annotation:
>> @OneToOne(mappedBy="underlyingInstrument")
>>
>> to the instrumentDomain element. Did you try this?
>> If not can you try and let me know what happens.
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I thought there was too much annotation to produce something so
>>> simple. I made the mistake of starting out from the many side and
>>> looking at it as a one to one, i.e. I have only one parent from this
>>> end.
>>>
>>> So I removed the underlyinginstrument element as suggested, which
>>> left me with this
>>>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Id @GeneratedValue(strategy=IDENTITY)
>>> @OneToOne(mappedBy="underlyingInstrument")
>>> </xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> .....
>>>
>>> This does not make sense as there is no underlyingInstrument anymore.
>>> So I removed the @OneTone annotation.
>>>
>>> So I used a simple element to generate the foreign key
>>>
>>> <xsd:element ecore:opposite="instrumentDomain" minOccurs="0"
>>> maxOccurs="unbounded" name="underlyingInstrument"
>>> type="gensec:InstrumentDomain" >
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">
>>> @Column(name="underlyinginstrument")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> This worked as expected, but it did ignore my request for a column
>>> named underlyinginstrument and instead created one called
>>> instrumentdomain. I tried @JoinColumn instead but that created a
>>> separate column with that name and left the instrumentdomain column
>>> in place, obviously not a valid annotation combination.
>>>
>>> If I can get it to name the column as I want it then I am there.
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> For a unidirectional relation it is enough to have a
>>>> instrumentdomain in the child which points to the parent (like what
>>>> you mention in your last post). This is a many-to-one. To get this
>>>> just remove the underlyinginstrument element.
>>>>
>>>> In the model you showed two posts back you have a bidirectional
>>>> relation (with maxOccurs="1" on both sides) making it a one-to-one.
>>>> This one-to-one can be modelled with one foreign key column on one
>>>> of the sides of the association.
>>>> So as far as I can see adding the @OneToOne to the instrumentDomain
>>>> element would do the trick, forcing the column to be handled by the
>>>> underlyingInstrument.
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> It is in InstrumentDomain. When I said that it is 'self
>>>>> referential', I mean that InstrumentDomain has a relationship with
>>>>> itself. In other words I want a InstrumentDomain to have a
>>>>> reference to a parent InstrumentDomain. InstrumentDomain.id -<
>>>>> InstrumentDomain.underlyingInstrument
>>>>>
>>>>> Is that possible?
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> I think the @OneToOne should be in the instrumentDomain element
>>>>>> because that's the opposite of the underlyingInstrument.
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I saw the thread on @OneToOne from Roland Brand but find the
>>>>>>> switch from ECore annotation to XSD annotation not straightforward.
>>>>>>>
>>>>>>> I must be missing something still
>>>>>>>
>>>>>>> I have
>>>>>>>
>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>> <xsd:sequence>
>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @ManyToOne
>>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>> .....
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @Id @GeneratedValue(strategy=IDENTITY)
>>>>>>> @OneToOne(mappedBy="underlyingInstrument")
>>>>>>> </xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> .....
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="instrumentDomain"
>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>
>>>>>>>
>>>>>>> What I don't get is that this is self referential, and the only
>>>>>>> 'other side' there is is the generated primary key for the
>>>>>>> element, a attribute. So if attribute does not support @OneToOne
>>>>>>> then how do you specify the 'other side'?
>>>>>>>
>>>>>>> It gives me -
>>>>>>> Exception in thread "main"
>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>> The eclass: HbAnnotatedEAttribute does not have an efeature for
>>>>>>> OneToOne
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:130)
>>>>>>>
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> This issue seems familiar :-)
>>>>>>>>
>>>>>>>> Hmm, afaics there are two sides:
>>>>>>>> InstrumentDomain.underlyingInstrument <-->
>>>>>>>> InstrumentDomain.instrumentDomain
>>>>>>>>
>>>>>>>> Teneo will generate a one-to-one on one side and the many-to-one
>>>>>>>> on the other side (can you check?). The foreign key field is
>>>>>>>> controlled/set by the many-to-one. In this case Teneo chooses to
>>>>>>>> place the manytoone in InstrumentDomain.instrumentDomain. I
>>>>>>>> think you can solve this by setting the @OneToOne annotation in
>>>>>>>> InstrumentDomain.instrumentDomain with mappedBy having the
>>>>>>>> efeature name of the other side.
>>>>>>>> Then keep the joincolum annotation in underlyinginstrument.
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> This might be useful too, from, the generated hibernate.hbm.xml
>>>>>>>>> file for this column
>>>>>>>>>
>>>>>>>>> <one-to-one name="underlyingInstrument"
>>>>>>>>> entity-name="InstrumentDomain"
>>>>>>>>> foreign-key="instrumentdomain_underlyinginstrument"
>>>>>>>>> cascade="all" lazy="false" property-ref="instrumentDomain"/>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I tried both
>>>>>>>>>>
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>> @JoinColumn(name="underlyinginstrument")
>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> and
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>> @Column(name="underlyinginstrument")
>>>>>>>>>> </xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>
>>>>>>>>>> Neither changed the column name generated. Each time I made
>>>>>>>>>> sure I dropped th etabl ein the schema, did "Reload..." on the
>>>>>>>>>> .genmodel, then "Generate Model Code", then ran my main class
>>>>>>>>>> to do the datastore initialize(). The table is recreated, but
>>>>>>>>>> with INSTRUMENTDOMAIN as the FK column name.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>> Martin Taal wrote:
>>>>>>>>>>> Hi David,
>>>>>>>>>>> Does @JoinColumn work here? Also it is possible the name
>>>>>>>>>>> needs to be enclosed with "
>>>>>>>>>>>
>>>>>>>>>>> gr. Martin
>>>>>>>>>>>
>>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I want a self referential 0..1 relationship. So have the
>>>>>>>>>>>> element defined like this
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:complexType name="InstrumentDomain">
>>>>>>>>>>>> <xsd:sequence>
>>>>>>>>>>>> <xsd:element ecore:opposite="instrumentDomain"
>>>>>>>>>>>> minOccurs="0" maxOccurs="1" name="underlyingInstrument"
>>>>>>>>>>>> type="gensec:InstrumentDomain" >
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>>> source="teneo.jpa">@Column(name=underlyinginstrument)</xsd:appinfo >
>>>>>>>>>>>>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>> .....
>>>>>>>>>>>> </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="instrumentDomain"
>>>>>>>>>>>> type="gensec:InstrumentDomain" />
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> What I get is a column name INSTRUMENTDOMAIN as the foreign
>>>>>>>>>>>> key, not underlyinginstrument as I expected. Anything else I
>>>>>>>>>>>> need to do to force the name I need?
>>>>>>>>>>>>
>>>>>>>>>>>> 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
Previous Topic:[CDO] + [Teneo] problems cdo_resources doesn't exist
Next Topic:Not a valid classifier on windows standalone application
Goto Forum:
  


Current Time: Fri Apr 26 23:39:53 GMT 2024

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

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

Back to the top