openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <>
Subject RE: Collection field part of a compound primary key
Date Thu, 19 Jul 2007 17:30:21 GMT

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
class Holiday {
  long hid;

  List<HolidayElement> elements;
class HolidayElement {
  Date date;
  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



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:
Sent from the OpenJPA Users mailing list archive at

View raw message