JPA primary key problem

How to use annotations for this classes:

publicclass Document

{

privateint id;

...

}

publicclass DocumentItem

{

privateint id;

private Document document;

...

}

to obtain that schema (especially primary key constraint for table documentitem):

create table document(

id decimal not null,

...,

primary key(id)

)

create table documentitem(

id decimal not null,

document_id decimal not null,

...,

primary key(id, document_id)

)

alter table documentitem add constraint fk_documentitem_1

foreign key (document_id) references document

[1088 byte] By [margar@o2.pla] at [2007-11-27 5:46:07]
# 1

OK. I can add the additional field to class DocumentItem like in sun's tutorial:

@Entity

public class Document

{

@Id

private int id;

...

}

@Entity

@IdClass(DocumentItemId.class)

public class DocumentItem

{

@Id

private int id;

@Id

@Column(name="DOCUMENT_ID", nullable=false, insertable=false, updatable=false)

private int documentId;

@ManyToOne

@JoinColumn(name="DOCUMENT_ID", nullable=false)

private Document document;

...

}

but this filed is redundant. Is it better way to resolve this problem?

margar@o2.pla at 2007-7-12 15:28:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
An IdClass and your mapping is the perfectly correct way to handle this situation.
mf125085a at 2007-7-12 15:28:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...