Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] @Embeddable and @mapsId

Hello Luke,

Yes mapsId can be used, but your primary key for B is set up wrong for it to be used. Please review the specification, as it shows in the examples that B's ID either needs to be A's id or contain it. Ie:

public class B {
 @EmbeddedId APK id;



public class BPK {
 APK aId;

Mapsid would then refer to id or aId depending on the situation. Why are you attempting this with an embeddable object, and did you get the previous situation working? You might want to try a less complex object model first and verify that it is working before moving onto derrived ids - for instance, B and SubjectFile seem to both use an id field that could be used as a unique primary key (bid and fileTpId),
rather than be used as a component of a composite pk.


luke2010 wrote:
here is one scenario
there are two entity A, B, A has PK class APK including aId, bId, B has BPK
class including aId, bId as well. they have oneToone relationship. Can I use
annotation @MapsId on @OnetoOne relationship on entity B?
 // parent entity has simple primary key

    public class A {
       @EmbeddedId APK id;
@OneToOne(optional=false, mappedBy="a", cascade = ALL, targetEntity =
      private B b;

    public class B {
       @EmbeddedId BPK id;
@OneToOne(optional = false)
		@JoinColumn(name="A_ID", referencedColumnName="A_ID"),
		@JoinColumn(name="B_ID", referencedColumnName="B_ID"),
		@MapsId ??????
		private A a;
    public class BPK {
       int aId name;
@Column(name="B_ID") long bId; }

Back to the top