Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Primary key foreign key entity relationship issue

What version are you using?  Can you provide the error and the stack trace?

Regards,
Chris

luke2010 wrote:
In my case under eclipseLink 2.0, there are A, B  and C entity class.  A has
1:M relationship to B, B has 1:1 relationship to C.  A has PK aId, B has PK
aId, bId, C has PK aId and bId, aId is part of PK of B and C, and also FK to
A.
@Entity
class A {

	@Id
	@Column(name="A_ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private String aId;
	
	@OneToMany( mappedBy="a",  cascade = ALL, targetEntity=B.class)
	@PrivateOwned
	private Set bs;
}

1. why mappedBy="a" is always complaining that Attribute named "a" has
invalid mapping for this relationship. If I removed the @Id in class B for
@ManyToOne, this complain will disappear.
@Entity
class B {

	@Column(name="B_ID")
	@Id
	private int bId;
	
	
    @ManyToOne(cascade = ALL)
	@JoinColumn(name="A_ID", referencedColumnName="A_ID")
	@Id
	@XmlTransient
	private A a;
	
	
	@OneToOne(optional=false, mappedBy="b", cascade = ALL, targetEntity =
C.class)
    @PrivateOwned
    private C c;
}


1. why mappedBy="b" is always complaining that Attribute named "b" has
invalid mapping for this relationship. If I removed the @Id in class C for
@ManyToOne, this complain will disappear. But it will compain other thing
"Entity "C" has no Id or EmbeddedId"

@Entity
Class C{

	@OneToOne(optional = false)
	@JoinColumns({
		@JoinColumn(name="A_ID", referencedColumnName="A_ID", insertable = false,
updatable = false),
		@JoinColumn(name="B_ID", referencedColumnName="B_ID", insertable = false,
updatable = false),
		})
    @XmlTransient		
    @Id
	private B b;
}




Back to the top