Home » Modeling » EMF » OneToMany not working as expected...
OneToMany not working as expected... [message #431224] |
Thu, 02 July 2009 22:45 |
Roberto Leibman Messages: 6 Registered: July 2009 |
Junior Member |
|
|
Hi again!
I have a problem with a OneToMany relationship that isn't behaving as I
expect it.
I have two tables, it's a unidirectional one-to-many relationship where
the join happens on a column that is NOT the primary column of the 'one'
side. I'm annotating this as:
@OneToMany(fetch=FetchType.LAZY, indexed=false)
@JoinColumn(name="GRP_ID", referencedColumnName="CLI_ID")
When the query to retrieve the "many" is run, the column of the "many"
is correct, but the bound parameter turns out to be the primary key of
the "one" instead of the CLI_ID that I expect, so I get NO results.
Thanks,
Roberto Leibman
---------------------------------
Here're the xsds, edited for brevity:
<xsd:complexType name="Foo">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Entity @Table( name="FOO_TABLE"
)</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="BagOfBars" type="Bar" minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>
@OneToMany(fetch=FetchType.LAZY, indexed=false)
@JoinColumn(name="GRP_ID", referencedColumnName="CLI_ID")
</xsd:appinfo>
<xsd:documentation></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="dnmSK" type="xsd:int" default='0'>
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">
@Id @Column(name="DNM_SK", nullable="false",insertable = true,
updatable = false)
@GeneratedValue(strategy=SEQUENCE,generator="excludeClientSequence ")
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute default="" name="clientId" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Column(name="CLI_ID",
length="8")</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name='Bar'>
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>@Entity
@Table(name="BAR_TABLE")</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name='barKey'
type='BarKey'>
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>
@Embedded @AttributeOverrides({@AttributeOverride(name="groupId",
column=@Column(name="GRP_ID")),@AttributeOverride(name="classId ",
column=@Column(name="CLAS_ID"))})
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name='BarKey'>
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>@Embeddable</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
</xsd:sequence>
<xsd:attribute name='groupId' type='xsd:string' >
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>@Column(name="GRP_ID",
nullable=false)</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name='classId' type='xsd:string' >
<xsd:annotation>
<xsd:appinfo source='teneo.jpa'>@Column(name="CLAS_ID",
nullable=false)</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
----------------
And the mapping that I get (note the total absence of cli_id anywhere in
the 'bag')
-----------------------
<class name="FooImpl" entity-name="Foo" abstract="false" lazy="false"
table="FOO_TABLE">
<meta attribute="eclassName">Foo</meta>
<id name="dnmSK" type="int" unsaved-value="0">
<column not-null="true" unique="false" name="dnm_sk"/>
<generator class="sequence">
<param name="sequence">PRDS0001</param>
<param name="initialValue">1</param>
<param name="allocationSize">50</param>
</generator>
</id>
<bag name="statusLogEntries" inverse="true" lazy="true"
cascade="all,delete-orphan">
<key update="true" foreign-key="foo_bagofbars">
<column name="grp_id" not-null="false" unique="false"/>
</key>
<one-to-many entity-name="StatusLog"/>
</bag>
</class>
|
|
|
Re: OneToMany not working as expected... [message #431226 is a reply to message #431224] |
Fri, 03 July 2009 07:01 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Roberto,
Yes the key misses a property-ref.
Can you enter a bugzilla with this example model attached? Then I will take care of this.
gr. Martin
Roberto Leibman wrote:
> Hi again!
>
> I have a problem with a OneToMany relationship that isn't behaving as I
> expect it.
>
> I have two tables, it's a unidirectional one-to-many relationship where
> the join happens on a column that is NOT the primary column of the 'one'
> side. I'm annotating this as:
>
> @OneToMany(fetch=FetchType.LAZY, indexed=false)
> @JoinColumn(name="GRP_ID", referencedColumnName="CLI_ID")
>
>
> When the query to retrieve the "many" is run, the column of the "many"
> is correct, but the bound parameter turns out to be the primary key of
> the "one" instead of the CLI_ID that I expect, so I get NO results.
>
> Thanks,
>
> Roberto Leibman
>
> ---------------------------------
> Here're the xsds, edited for brevity:
>
> <xsd:complexType name="Foo">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Entity @Table( name="FOO_TABLE"
> )</xsd:appinfo>
> </xsd:annotation>
> <xsd:sequence>
> <xsd:element name="BagOfBars" type="Bar" minOccurs="0"
> maxOccurs="unbounded">
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>
> @OneToMany(fetch=FetchType.LAZY, indexed=false)
> @JoinColumn(name="GRP_ID", referencedColumnName="CLI_ID")
> </xsd:appinfo>
> <xsd:documentation></xsd:documentation>
> </xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="dnmSK" type="xsd:int" default='0'>
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">
> @Id @Column(name="DNM_SK", nullable="false",insertable = true,
> updatable = false)
> @GeneratedValue(strategy=SEQUENCE,generator="excludeClientSequence ")
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute default="" name="clientId" type="xsd:string">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Column(name="CLI_ID",
> length="8")</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
> <xsd:complexType name='Bar'>
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>@Entity
> @Table(name="BAR_TABLE")</xsd:appinfo>
> </xsd:annotation>
> <xsd:sequence>
> <xsd:element name='barKey'
> type='BarKey'>
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>
> @Embedded @AttributeOverrides({@AttributeOverride(name="groupId",
> column=@Column(name="GRP_ID")),@AttributeOverride(name="classId ",
> column=@Column(name="CLAS_ID"))})
> </xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name='BarKey'>
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>@Embeddable</xsd:appinfo>
> </xsd:annotation>
> <xsd:sequence>
> </xsd:sequence>
> <xsd:attribute name='groupId' type='xsd:string' >
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>@Column(name="GRP_ID",
> nullable=false)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name='classId' type='xsd:string' >
> <xsd:annotation>
> <xsd:appinfo source='teneo.jpa'>@Column(name="CLAS_ID",
> nullable=false)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
>
> ----------------
> And the mapping that I get (note the total absence of cli_id anywhere in
> the 'bag')
> -----------------------
>
> <class name="FooImpl" entity-name="Foo" abstract="false" lazy="false"
> table="FOO_TABLE">
> <meta attribute="eclassName">Foo</meta>
> <id name="dnmSK" type="int" unsaved-value="0">
> <column not-null="true" unique="false" name="dnm_sk"/>
> <generator class="sequence">
> <param name="sequence">PRDS0001</param>
> <param name="initialValue">1</param>
> <param name="allocationSize">50</param>
> </generator>
> </id>
> <bag name="statusLogEntries" inverse="true" lazy="true"
> cascade="all,delete-orphan">
> <key update="true" foreign-key="foo_bagofbars">
> <column name="grp_id" not-null="false" unique="false"/>
> </key>
> <one-to-many entity-name="StatusLog"/>
> </bag>
> </class>
--
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
|
|
| |
Goto Forum:
Current Time: Fri Sep 20 00:46:21 GMT 2024
Powered by FUDForum. Page generated in 0.03820 seconds
|