Java 日食层次错误

Java 日食层次错误,java,jpa,eclipselink,eclipse-virgo,Java,Jpa,Eclipselink,Eclipse Virgo,我正在尝试与Virgo和EclipseLink合作,并基于Greenpage项目实现一个应用程序 我已经实现了一个层次结构,但是我得到了一个wierd错误(使用EclipseLink): 层次结构: 实体将注释从访问器移动到字段声明,并将字段可访问性更改为受保护 @MappedSuperclass public abstract class Entity implements Serializable { private static final long serialVersionU

我正在尝试与Virgo和EclipseLink合作,并基于Greenpage项目实现一个应用程序

我已经实现了一个层次结构,但是我得到了一个wierd错误(使用EclipseLink):

层次结构:


实体将注释从访问器移动到字段声明,并将字段可访问性更改为受保护

@MappedSuperclass
public abstract class Entity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    protected Long id;

    public Long getId() {
        return id;
    }

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

好的,Kevin Bowersox的答案告诉我正确的答案:我更改所有受保护的字段,并将注释更改为字段。这将导致良好的工作状态;)

属性访问是一种完全有效的方法。@user872846您能发布新的错误吗?尝试保护抽象类中的所有字段。我怀疑EclipseLink可能需要直接访问字段,而私有作用域阻止了这一点。当然,但对于其他类,例外情况是相同的。我将所有字段更改为“受保护”,但没有成功;(凯文的解决方案中有什么不适合你呢?我看不出有什么不同。
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;

}
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.
@MappedSuperclass
public abstract class Entity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    protected Long id;

    public Long getId() {
        return id;
    }

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