[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] @OneToOne with @MapsId and @IdClass
|
Hi,
I am trying to implement @OneToOne with @MapsId and @IdClass
(preferably in the most basic way possible).
If I could find a working example on the web then I would be happy.
My code does not work (maven sample project available):
@Entity
@IdClass(value = RequiredPk.class)
public class Required implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Temporal(javax.persistence.TemporalType.DATE)
private Date dateCeated;
@Id
private String name;
@Entity
@IdClass(value = RequiredPk.class)
public class Optional implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Temporal(javax.persistence.TemporalType.DATE)
@Column(insertable = false, updatable = false)
private Date dateCeated;
@Id
@Column(insertable = false, updatable = false)
private String name;
@OneToOne
@MapsId
private Required required;
public class RequiredPk implements Serializable {
private static final long serialVersionUID = 1L;
private Date dateCeated;
private String name;
....
final String name = "name";
final Date date = new Date();
Required required = new Required();
required.setName(name);
required.setDateCeated(date);
em.persist(required);
em.flush();
Optional optional = new Optional();
optional.setRequired(required);
em.persist(optional);
Exception Description: Trying to set value [RequiredPk{dateCeated=Sat
Jul 05 18:03:03 NZST 2014, name=name}] for instance variable [name] of
type [java.lang.String] 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
java.lang.String field mapsid.entity.Optional.name to
mapsid.entity.RequiredPk
Mapping:
org.eclipse.persistence.mappings.DirectToFieldMapping[name-->OPTIONAL.DATECEATED]
Descriptor: RelationalDescriptor(mapsid.entity.Optional -->
[DatabaseTable(OPTIONAL)])
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:499)
What would be your recommendation in this scenario? I found that
EclipseLink / JPA has simple solutions for most cases so I guess I am
just missing something.
Many thanks!
Bernard
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
Attachment:
OneToOneMapsIdIdClass.zip
Description: Binary data