Ok guys, i have finally notice my error. The key factor is this
line Pinaki.
public long hid; // same name and type of Holiday's identity
You were telling all the time, but you know, sometimes happens
that you read a line a million times without noticing the bug.
Now everything makes much more sense for me. Indeed, the Id
class is used by the Developer to suggets JPA how to build the foreign
key correctly.
Just look at the sql statements JPA performs to create the
tables:
9017 rountingenginejpa TRACE [main] openjpa.jdbc.SQL - <t 20226877,
conn 13178395> executing stmnt 12191562 CREATE TABLE Screening (scrId
INTEGER NOT NULL, PRIMARY KEY (scrId))
9251 rountingenginejpa TRACE [main] openjpa.jdbc.SQL - <t 20226877,
conn 13178395> [234 ms] spent
9251 rountingenginejpa TRACE [main] openjpa.jdbc.SQL - <t 20226877,
conn 13327669> executing stmnt 24635060 CREATE TABLE ScreeningElement
(ScrEntry VARCHAR(255) NOT NULL, screening_scrId INTEGER NOT NULL,
PRIMARY KEY (ScrEntry, screening_scrId))
9407 rountingenginejpa TRACE [main] openjpa.jdbc.SQL - <t 20226877,
conn 13327669> [156 ms] spent
9407 rountingenginejpa TRACE [main] openjpa.jdbc.SQL - <t 20226877,
conn 14919969> executing stmnt 2115134 ALTER TABLE ScreeningElement ADD
FOREIGN KEY (screening_scrId) REFERENCES Screening (scrId)
Know i can clearly see the primary and the foreign key correctly
created.
Thanks for all, see you.
-----Original Message-----
From: Pinaki Poddar [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 19, 2007 7:30 PM
To: [email protected]
Subject: RE: Collection field part of a compound primary key
The domain model requires to define a compound identity for
HolidayElement
{HolidayDate, ParentHoliday} -- is that right?
If this is the case, OpenJPA supports this feature as it allows a
Relation
to be part of compound identity for an Entity. the outline of the model
can
be:
==========================================
@Entity
class Holiday {
@Id
long hid;
@OneToMany(mappedBy="parent")
List<HolidayElement> elements;
}
===========================================
@Entity
@IdClass(HolidayAsPartOfCompoundId.class)
class HolidayElement {
@Id
Date date;
@Id
@ManyToOne
Holiday parent;
}
===========================================
public class HolidayAsPartOfCompoundId {
public Date date; // same name and type of HolidayElement's first
identity field
public long hid; // same name and type of Holiday's identity
// Of course, you have to write equals() and hashCode() method of this
compound Id class.
===============================================
Further reading
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_oi
d_entitypk
http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_overview_pc
_identitycls
Find attached the Holiday classes. Holiday is formed by several
HolidayElements. A HolidayElement is mainly identified by its date, but
several HolidayElement can share the same date if they are from
diffetent Holidays. Here the primary Key is formed by the date and the
Holiday id (which is a foreign key to Holiday).
--
View this message in context:
http://www.nabble.com/Collection-field-part-of-a-compound-primary-key-tf
4110891.html#a11694049
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Confidentiality Statement:
This message is intended only for the individual or entity to which it is
addressed. It may contain privileged, confidential information which is exempt
from disclosure under applicable laws. If you are not the intended recipient,
please note that you are strictly prohibited from disseminating or distributing
this information (other than to the intended recipient) or copying this
information. If you have received this communication in error, please notify us
immediately by return email.
-----------------------------