[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] @Embeddable and @mapsId
|
Chris, thanks for your solution. I followed it, and type the snippet below:
=======
@Entity
public class A {
@EmbeddedId APK id;
...
@OneToOne(optional=false, mappedBy="a", cascade = ALL, targetEntity =
B.class)
@PrivateOwned
private B b;
...
}
@Entity
public class B {
@EmbeddedId APK id;
...
@OneToOne(optional = false)
@JoinColumns({
@JoinColumn(name="A_ID", referencedColumnName="A_ID"),
@JoinColumn(name="B_ID", referencedColumnName="B_ID"),
})
@MapsId
private A a;
}
@Embeddable
public class BPK {
@Column(name="A_ID")
int aId name;
@Column(name="B_ID")
long bId;
}
===============================
I tried @MapsId or @MapsId("id"), either of them works for me. and here is
the error message I got
----------------
Thread(Thread[Main Thread,5,main])--Exception [EclipseLink-32] (Eclipse
Persistence Services - 2.0.1.v20100213-r6600):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to set value [10005699] for instance variable
[id] of type [com.entities.copy.APK] in the object. The specified object is
not an instance of the class or interface declaring the underlying field, or
an unwrapping conversion has failed.
Internal Exception: java.lang.IllegalArgumentException: Can not set
com.entities.copy.APK field com.entities.copy.B.id to java.lang.String
Mapping: org.eclipse.persistence.mappings.AggregateObjectMapping[id]
===================================
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?
>
> ==========================
> @Entity
> public class A {
> @EmbeddedId APK id;
> ...
>
>
> @OneToOne(optional=false, mappedBy="a", cascade = ALL, targetEntity
> = B.class)
> @PrivateOwned
> private B b;
> ...
> }
>
> @Entity
> public class B {
> @EmbeddedId BPK id;
> ...
>
>
> @OneToOne(optional = false)
> @JoinColumns({
> @JoinColumn(name="A_ID", referencedColumnName="A_ID"),
> @JoinColumn(name="B_ID", referencedColumnName="B_ID"),
> })
> @MapsId ??????
> private A a;
> }
>
>
> @Embeddable
> public class BPK {
> @Column(name="A_ID")
> int aId name;
>
> @Column(name="B_ID")
> long bId;
> }
> ======================================
> I tried @MapsId at the question mark location, but I don't know which
> attribute name to provide. If i dont' provide anything, i got error below:
>
> ---------------------------------
> Caused by: Exception [EclipseLink-7316] (Eclipse Persistence Services -
> 2.0.1.v20100213-r6600):
> org.eclipse.persistence.exceptions.ValidationException
> Exception Description: The mapped by id value [a] from the mapping
> attribute [field a] is invalid. An equivalent attribute with that name
> must be defined on the id class [class com.package.BPK]
>
--
View this message in context: http://old.nabble.com/%40Embeddable-and-%40mapsId-tp27913035p27933367.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.