0

Virgo と EclipseLink を使用して、Greenpage プロジェクトに基づいたアプリケーションを実装しようとしています。

階層を実装しましたが、奇妙なエラーが発生します (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.

階層:

Entity <- NamedEntity <- Person <- ... - Person を拡張するその他のクラス

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 によって投稿された回答 (多くの感謝!) を助けた.部分的に ;)。問題はさらに深くなります。Entity <- NamedEntity <- Attribute <- 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.
4

2 に答える 2

3

注釈をアクセサーからフィールド宣言に移動し、フィールドのアクセシビリティを保護に変更します。

@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;
    }
}
于 2013-03-10T18:38:06.870 に答える
-1

OK、Kevin Bowersoxの回答により、正しい回答が得られました。保護されているすべてのフィールドを変更し、注釈をフィールドに変更します。これにより、正常に動作します;)。

于 2013-03-10T20:11:34.187 に答える