Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo/JPA] can an @EmbeddedId use type=xsd:IDREF?
[Teneo/JPA] can an @EmbeddedId use type=xsd:IDREF? [message #425215] Wed, 19 November 2008 21:09 Go to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
I have an @EmbeddedId compound key problem.
LensToLensOptionRelation is a join table relating two object.
Because it's a join table it has a composite key.

Here's the XSD for one side of the relationship:

<!-- ============================================= -->
<xsd:complexType name="LensToLensOptionRelation">
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Entity @Table( name="CSAZZZZT" )
</xsd:appinfo></xsd:annotation>

<xsd:sequence>

<xsd:element name="key"
type=" com.vsp.supplier.model.lens:LensToLensOptionRelationComposit eKey ">
<xsd:annotation><xsd:appinfo ource="teneo.jpa">
@EmbeddedId
</xsd:appinfo></xsd:annotation>
</xsd:element>
<!-- ============================================= -->

So basically, the LensToLensOptionRelation uses a composite key for it's
ID. So far so good.

First off, I made the relationship a int that returns the ID of the
object that the foreign key is referring to.
If the composite key only uses primitive types, it can do the query
correctly:

<!-- ============================================= -->
<xsd:complexType name="LensToLensOptionRelationCompositeKey">

<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Embeddable
</xsd:appinfo></xsd:annotation>

<xsd:sequence>
</xsd:sequence>

<xsd:attribute name="lensId" type="xsd:int">
<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Column(name="PRODUCT_CD")
</xsd:appinfo></xsd:annotation>
</xsd:attribute>
<!-- ============================================= -->

However, the lensId actually points to a lens object and I'd like a Lens
object returned in my generated API. So inside the composite key I
change it to look like this:

<!-- ============================================= -->
<xsd:complexType name="LensToLensOptionRelationCompositeKey">

<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Embeddable
</xsd:appinfo></xsd:annotation>

<xsd:sequence>
</xsd:sequence>

<xsd:attribute name="lensId"
type="xsd:IDREF" ecore:reference="com.vsp.supplier.model.lens:Lens"
>

<xsd:annotation><xsd:appinfo source="teneo.jpa">
@Column(name="PRODUCT_CD")
</xsd:appinfo></xsd:annotation>
</xsd:attribute>
<!-- ============================================= -->

The @Column info is the same, but now I'm asking for a reference to an
actual Lens object instead of just an int.

Unfortunately, this makes the query fail.
Instead of looking for PRODUCT_CD the query looks like this:
select this_.lens_lensid_lensid as lens1_8_0_

when it should be something like
select this_.product_cd

I assume it's generating that out of the object names, but this is a
legacy database, so that column name doesn't exist. It seems like it's
ignoring the @Column's name attribute.

Any ideas, or am I violating the laws of physics here?

Jason Henriksen
Re: [Teneo/JPA] can an @EmbeddedId use type=xsd:IDREF? [message #425218 is a reply to message #425215] Wed, 19 November 2008 23:10 Go to previous messageGo to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
GAH! Problem was in my JPA annotation. Teneo work fine.
(Brilliantly in fact)

The corrected XSD is printed here in case it helps anyone else out:

<xsd:complexType name="LensToLensOptionRelationCompositeKey">

<xsd:annotation><xsd:appinfo ource="teneo.jpa">
@Embeddable</xsd:appinfo>
</xsd:annotation>

<xsd:sequence>
</xsd:sequence>

<xsd:attribute name="lensId"
type="xsd:IDREF"
ecore:reference="com.vsp.supplier.model.lens:Lens">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@ManyToOne
@JoinColumn(name="PRODUCT_CD" insertable="false" updatable="false")
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>


jason henriksen wrote:
> I have an @EmbeddedId compound key problem.
> LensToLensOptionRelation is a join table relating two object.
> Because it's a join table it has a composite key.
>
> Here's the XSD for one side of the relationship:
>
> <!-- ============================================= -->
> <xsd:complexType name="LensToLensOptionRelation">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Entity @Table( name="CSAZZZZT" )
> </xsd:appinfo></xsd:annotation>
>
> <xsd:sequence>
>
> <xsd:element name="key"
> type=" com.vsp.supplier.model.lens:LensToLensOptionRelationComposit eKey ">
> <xsd:annotation><xsd:appinfo ource="teneo.jpa">
> @EmbeddedId
> </xsd:appinfo></xsd:annotation>
> </xsd:element>
> <!-- ============================================= -->
>
> So basically, the LensToLensOptionRelation uses a composite key for it's
> ID. So far so good.
>
> First off, I made the relationship a int that returns the ID of the
> object that the foreign key is referring to.
> If the composite key only uses primitive types, it can do the query
> correctly:
>
> <!-- ============================================= -->
> <xsd:complexType name="LensToLensOptionRelationCompositeKey">
>
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Embeddable
> </xsd:appinfo></xsd:annotation>
>
> <xsd:sequence>
> </xsd:sequence>
>
> <xsd:attribute name="lensId" type="xsd:int">
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Column(name="PRODUCT_CD")
> </xsd:appinfo></xsd:annotation>
> </xsd:attribute>
> <!-- ============================================= -->
>
> However, the lensId actually points to a lens object and I'd like a Lens
> object returned in my generated API. So inside the composite key I
> change it to look like this:
>
> <!-- ============================================= -->
> <xsd:complexType name="LensToLensOptionRelationCompositeKey">
>
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Embeddable
> </xsd:appinfo></xsd:annotation>
>
> <xsd:sequence>
> </xsd:sequence>
>
> <xsd:attribute name="lensId"
> type="xsd:IDREF"
> ecore:reference="com.vsp.supplier.model.lens:Lens"
> >
>
> <xsd:annotation><xsd:appinfo source="teneo.jpa">
> @Column(name="PRODUCT_CD")
> </xsd:appinfo></xsd:annotation>
> </xsd:attribute>
> <!-- ============================================= -->
>
> The @Column info is the same, but now I'm asking for a reference to an
> actual Lens object instead of just an int.
>
> Unfortunately, this makes the query fail.
> Instead of looking for PRODUCT_CD the query looks like this:
> select this_.lens_lensid_lensid as lens1_8_0_
>
> when it should be something like
> select this_.product_cd
>
> I assume it's generating that out of the object names, but this is a
> legacy database, so that column name doesn't exist. It seems like it's
> ignoring the @Column's name attribute.
>
> Any ideas, or am I violating the laws of physics here?
>
> Jason Henriksen
Re: [Teneo/JPA] can an @EmbeddedId use type=xsd:IDREF? [message #425220 is a reply to message #425218] Wed, 19 November 2008 23:27 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Good to hear! I was just about to let you know that I would be looking at your post tomorrow morning...

gr. Martin

jason henriksen wrote:
>
> GAH! Problem was in my JPA annotation. Teneo work fine.
> (Brilliantly in fact)
>
> The corrected XSD is printed here in case it helps anyone else out:
>
> <xsd:complexType name="LensToLensOptionRelationCompositeKey">
>
> <xsd:annotation><xsd:appinfo ource="teneo.jpa">
> @Embeddable</xsd:appinfo>
> </xsd:annotation>
>
> <xsd:sequence>
> </xsd:sequence>
>
> <xsd:attribute name="lensId"
> type="xsd:IDREF"
> ecore:reference="com.vsp.supplier.model.lens:Lens">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @ManyToOne
> @JoinColumn(name="PRODUCT_CD" insertable="false" updatable="false")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
>
>
> jason henriksen wrote:
>> I have an @EmbeddedId compound key problem.
>> LensToLensOptionRelation is a join table relating two object.
>> Because it's a join table it has a composite key.
>>
>> Here's the XSD for one side of the relationship:
>>
>> <!-- ============================================= -->
>> <xsd:complexType name="LensToLensOptionRelation">
>> <xsd:annotation><xsd:appinfo source="teneo.jpa">
>> @Entity @Table( name="CSAZZZZT" )
>> </xsd:appinfo></xsd:annotation>
>> <xsd:sequence>
>> <xsd:element name="key"
>> type=" com.vsp.supplier.model.lens:LensToLensOptionRelationComposit eKey ">
>> <xsd:annotation><xsd:appinfo ource="teneo.jpa">
>> @EmbeddedId
>> </xsd:appinfo></xsd:annotation> </xsd:element>
>> <!-- ============================================= -->
>>
>> So basically, the LensToLensOptionRelation uses a composite key for
>> it's ID. So far so good.
>>
>> First off, I made the relationship a int that returns the ID of the
>> object that the foreign key is referring to.
>> If the composite key only uses primitive types, it can do the query
>> correctly:
>>
>> <!-- ============================================= -->
>> <xsd:complexType name="LensToLensOptionRelationCompositeKey">
>>
>> <xsd:annotation><xsd:appinfo source="teneo.jpa">
>> @Embeddable
>> </xsd:appinfo></xsd:annotation>
>> <xsd:sequence>
>> </xsd:sequence>
>>
>> <xsd:attribute name="lensId" type="xsd:int">
>> <xsd:annotation><xsd:appinfo source="teneo.jpa">
>> @Column(name="PRODUCT_CD")
>> </xsd:appinfo></xsd:annotation>
>> </xsd:attribute>
>> <!-- ============================================= -->
>>
>> However, the lensId actually points to a lens object and I'd like a
>> Lens object returned in my generated API. So inside the composite key
>> I change it to look like this:
>>
>> <!-- ============================================= -->
>> <xsd:complexType name="LensToLensOptionRelationCompositeKey">
>>
>> <xsd:annotation><xsd:appinfo source="teneo.jpa">
>> @Embeddable
>> </xsd:appinfo></xsd:annotation>
>> <xsd:sequence>
>> </xsd:sequence>
>>
>> <xsd:attribute name="lensId"
>> type="xsd:IDREF"
>> ecore:reference="com.vsp.supplier.model.lens:Lens"
>> >
>>
>> <xsd:annotation><xsd:appinfo source="teneo.jpa">
>> @Column(name="PRODUCT_CD")
>> </xsd:appinfo></xsd:annotation>
>> </xsd:attribute>
>> <!-- ============================================= -->
>>
>> The @Column info is the same, but now I'm asking for a reference to an
>> actual Lens object instead of just an int.
>>
>> Unfortunately, this makes the query fail.
>> Instead of looking for PRODUCT_CD the query looks like this:
>> select this_.lens_lensid_lensid as lens1_8_0_
>>
>> when it should be something like
>> select this_.product_cd
>>
>> I assume it's generating that out of the object names, but this is a
>> legacy database, so that column name doesn't exist. It seems like
>> it's ignoring the @Column's name attribute.
>>
>> Any ideas, or am I violating the laws of physics here?
>>
>> Jason Henriksen


--

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:HibernateResource vs XmiResourceImpl performances ?
Next Topic:Existing genmodel not picked up
Goto Forum:
  


Current Time: Fri Feb 21 13:44:47 GMT 2020

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

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

Back to the top