Help with mapping a inherited relationship as a @OneToOne [message #533447] |
Thu, 13 May 2010 18:45  |
Eclipse User |
|
|
|
EclipseLink 2.0
GlassFish 3.0
I have a parent/child relationship going on in the database that I inherited. The relationship is actually using inheritance, although the constraints are not present in the database. Rather than defining this relationship in Java using inheritance, I want to define a has-a relationship instead.
Parent table of Party, which has a PrimaryKey defined as follows:
public class Party {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="PartyID")
protected Integer id;
....
}
One of the children is Lead and is defined as follows:
public class Lead {
@Id
@Column(name="LeadId")
private Integer id;
@JoinColumn(name = "LeadId", referencedColumnName = "PartyID", nullable = false, updatable = false)
@OneToOne(optional = false)
private Party party;
}
My problem is that EclipseLink is complaining with the following:
Exception Description: Multiple writable mappings exist for the field [Lead.LeadId]. Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.OneToOneMapping[party]
Descriptor: RelationalDescriptor(com.intraxinc.core.persistence.entity.Lead --> [DatabaseTable(Lead)])
So I know that I have something incorrectly defined but I need help with getting this relationship defined correctly. I know I'm overlooking something, probably very small. I know that the Lead class cannot have a generated Id field as it must be the same as the Party.partyId.
Thanks for the help....
|
|
|
|
|
|
|
Re: Help with mapping a inherited relationship as a @OneToOne [message #534943 is a reply to message #534902] |
Thu, 20 May 2010 14:10  |
Eclipse User |
|
|
|
Yes, the default for @MapsId is the field defined with @Id or @EmbeddedId.
Dali is part of the Eclipse Java EE IDE, if you have created a JPA Project in Eclipse you are using Dali. I'm curious if you have used the most recent version of Entity generation. It was redone in Dali 2.2 which was included in the Eclipse 3.5 release, also available in the upcoming 3.6 release. It allows you to customize your relationships, entity names, attribute names, set up generators, etc. It also saves the wizard state if you want to regenerate.
We'd appreciate any feedback over on the Dali forum or in bugzilla, especially since you've worked in multiple IDEs.
Thanks,
Karen
|
|
|
Powered by
FUDForum. Page generated in 0.08544 seconds