Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] primary key (@id) in one-to-many relation

Hello,

I hope, this is a newbie question:
Is it possible to use a primary key (@id) field in an one-to-many relation?

My first class CClsItem, the 'one' part of the relation:

@Entity
@Table(name="C_CLS_ITEMS")
public class CClsItem implements Serializable {
...
//bi-directional many-to-one association to Note
@OneToMany(mappedBy="CClsItem")
public List<Note> getNotes() {
	return this.notes;
}
...
}

My second class, the 'many' part of the relation:
@Entity
@Table(name="NOTES")
public class Note implements Serializable {
...
//bi-directional many-to-one association to CClsItem
@ManyToOne
@JoinColumn(name="NOTESRECID", referencedColumnName="ROWNUMBER", nullable=false)
public CClsItem getCClsItem() {
	return this.CClsItem;
}
...
}
There should be a join NOTES.NOTESRECID=C_CLS_ITEMS.ROWNUMBER. But the field C_CLS_ITEMS.ROWNUMBER is the primary field. The eclipse tool 'generate entities from tables' removes my @id annotated field ROWNUMBER, if I use it in a relation.

I'm afraid I dont understand the JPA fundamentals?


Back to the top