Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Help for Entity derived from a MappedSuperclass with an EmbeddedId(MappedSuperclass with an EmbeddedId)
Help for Entity derived from a MappedSuperclass with an EmbeddedId [message #508402] Mon, 18 January 2010 11:30 Go to next message
kurt is currently offline kurt
Messages: 8
Registered: July 2009
Junior Member
Having an entity derived from a MappedSuperclass which contains a primarykeyclass.

Shouldn't that work? But trying to generate the table out of that, eclipselink gives me the following error:

Caused by: Exception [EclipseLink-7163] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class bsbs.MSC3] has both an @EmbdeddedId (on attribute [id]) and an @Id (on attribute []. Both ID types cannot be specified on the same entity.

The id-attribute (which eclipselink tells me is wrong) is empty (that is ok, because there is no @Id-field, so there is no mixing of embeddedid and id).

Below are the classes in question.

Any help would be very much welcome!

Thanks
Kurt


package bsbs;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class TPK
implements Serializable {

private static final long serialVersionUID = 1L;

@Column(name = "INST", nullable = false, length = 2)
private String id;

@Column(name = "NL", nullable = false, length = 2)
private String subid;

public String getId() {
return id;
}

public void setId(final String id) {
this.id = id;
}

public String getSubid() {
return subid;
}

public void setSubid(final String subid) {
this.subid = subid;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((subid == null) ? 0 : subid.hashCode());
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final TPK other = (TPK) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (subid == null) {
if (other.subid != null)
return false;
} else if (!subid.equals(other.subid))
return false;
return true;
}

}


package bsbs;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.EmbeddedId;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

@MappedSuperclass
public class MSC3
implements Serializable {

private static final long serialVersionUID = 1L;

@Version
private Timestamp version;

@EmbeddedId
protected TPK id;

public MSC3() {
super();
}

public Timestamp getVersion() {
return version;
}

public TPK getId() {
return id;
}

public void setId(final TPK id) {
this.id = id;
}

}


package bsbs;

import javax.persistence.Entity;

@Entity
public class T3
extends MSC3 {

private static final long serialVersionUID = 1L;

private String name;

public T3() {
super();
}

public String getName() {
return this.name;
}

public void setName(final String name) {
this.name = name;
}

}
Re: Help for Entity derived from a MappedSuperclass with an EmbeddedId [message #508583 is a reply to message #508402] Tue, 19 January 2010 09:35 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1017
Registered: July 2009
Senior Member
Hello,

Please file a bug for this issue and vote for it. The only workaround I can see in the mean time, is to use the embeddable as an IDClass and have the ID attributes on the mapped superclass directly. This would allow you to use the embeddable transparently so it can be set back once the bug is fixed.

Best Regards,
Chris
Re: Help for Entity derived from a MappedSuperclass with an EmbeddedId [message #508592 is a reply to message #508402] Tue, 19 January 2010 09:56 Go to previous messageGo to next message
kurt is currently offline kurt
Messages: 8
Registered: July 2009
Junior Member
did so: https://bugs.eclipse.org/bugs/show_bug.cgi?id=300051

thx
kurt
Re: Help for Entity derived from a MappedSuperclass with an EmbeddedId [message #519371 is a reply to message #508402] Mon, 08 March 2010 11:17 Go to previous message
Ed Randall is currently offline Ed Randall
Messages: 6
Registered: July 2009
Junior Member
We have also hit this problem, we are attempting to migrate a large project from Toplink Essentials to EclipseLink.

Works fine in 1.1.3

Bug occurs in 1.2.0 and 2.0.1

Ideally we'd like to use JPA2


Previous Topic:soft deletes and implications
Next Topic:Database Locks after upgrading from Toplink to Eclipselink
Goto Forum:
  


Current Time: Fri Aug 29 01:31:19 EDT 2014

Powered by FUDForum. Page generated in 0.01741 seconds