Help for Entity derived from a MappedSuperclass with an EmbeddedId [message #508402] |
Mon, 18 January 2010 11:30  |
Eclipse User |
|
|
|
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;
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07244 seconds