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

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.



Back to the top