Skip to main content

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

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;
}


-- 
View this message in context: http://old.nabble.com/Primary-key-foreign-key-entity-relationship-issue-tp27907840p27907840.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top