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,

I'm not sure what to say, as the error is clear that the problem is it is trying to insert a value of 10005699 into B's id attribute - which is set to be a type of APK. Are you sure you have this set up correctly? You are posting the BPK class when both A and B are now using APK, does the APK class look like the BPK? Maybe file a bug with a reproducible test case, as it is very difficult to determine what is going wrong with partial snippets, where anything excluded might be a factor in your issue. The test code provided does work though; it was pulled from EclipseLink's regression tests found within the model at:
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/advanced/derivedid

Best Regards,
Chris



luke2010 wrote:
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]




Back to the top