Skip to main content

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

James, 

both tables, C_CLS_ITEMS and NOTES have a primary key field ROWNUMBER. These fields are filled by the kernel of our ERP system. I use JPA only to read in these tables. 
I need the following one-to-many relation:
C_CLS_ITEMS (1)      NOTES (MANY)
@id                  @basic
ROWNUMBER ---------> NOTESRECID

If I define this relation with the Eclipse tool 'generate entities from tables', the tool removes the @id field ROWNUMBER in the generated class CClsItem. Than the CClsItem class has no primary key field.
I want to get the CClsItem data with an embedded Note list: List<Note> notes = cClsItem.getNote
I don't know: is it a problem of the Eclipse tool or of the definition of the primary key fields an the relation?

> -----Original Message-----
> From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-
> bounces@xxxxxxxxxxx] On Behalf Of James Sutherland
> Sent: Tuesday, January 19, 2010 3:40 PM
> To: eclipselink-users@xxxxxxxxxxx
> Subject: Re: [eclipselink-users] primary key (@id) in one-to-many
> relation
> 
> 
> Yes, that is the way it must be done.  You should have a Basic @Id
> attribute
> called rowNum in your CClsItem class.  What error are you getting doing
> this?
> 
> Perhaps include your complete mappings including how the @Id is mapped.
> 
> 
> Holger Rieß-2 wrote:
> >
> >
> > 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?
> >
> >
> 
> 
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James
> Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink
> ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> --
> View this message in context: http://old.nabble.com/primary-key-
> %28%40id%29-in-one-to-many-relation-tp27129847p27226802.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top