我正在尝试与处女座和EclipseLink合作并实施基于Greenpage项目的应用程序。EclipseLink层次结构错误
我实现了一个层次,但我得到(使用的EclipseLink)一个奇怪的错误:
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class model.Person] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
层次:
实体< - NamedEntity < - 人< - ...... - 其他类,扩展人
import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class Entity implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class NamedEntity extends Entity {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import pl.com.mgr.model.NamedEntity;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "discriminator")
public abstract class Person extends NamedEntity {
private static final long serialVersionUID = 1L;
}
编辑:由凯文Bowersox(非常感谢!)发布的答复...部分;)。问题进一步深入。我们现在是:实体< - NamedEntity < - 属性< - LecturerAttribute
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import model.NamedEntity;
@MappedSuperclass
public abstract class Attribute<T extends NamedEntity> extends NamedEntity {
private static final long serialVersionUID = 1L;
private T entity;
private String value;
@ManyToOne
@JoinColumn(name = "entity", nullable = false)
public T getEntity() {
return entity;
}
public void setEntity(T entity) {
this.entity = entity;
}
@Column(nullable = false)
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
import javax.persistence.Entity;
@Entity
public class LecturerAttribute extends Attribute<Lecturer> {
private static final long serialVersionUID = 1L;
}
和异常:
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class model.LecturerAttribute] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
属性访问是一个完全有效的使用。 – 2013-03-10 18:47:19
谢谢,但请参阅我的编辑;) – PastorPL 2013-03-10 18:48:49
@ user872846你能发布新的错误吗?尝试使抽象类中的所有字段都受保护。我怀疑EclipseLink可能需要直接访问该字段,而私有作用域正在阻止该字段。 – 2013-03-10 18:52:26