作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试与 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;
}
编辑:Kevin 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;
}
异常(exception)情况:
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.
最佳答案
将注释从访问器移至字段声明,并将字段可访问性更改为 protected 。
@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;
}
}
关于java - EclipseLink 层次结构错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15325965/
我正在尝试将多个水平链接的 Button 和 TextView 垂直链接为 View 集,但仍保持平面 View 层次结构。这是我的初始布局和代码:
到目前为止,我已经在Google BigQuery上训练了几种模型,目前我需要查看模型的外观(即架构,损失函数等)。 有没有办法获取这些信息? 最佳答案 仔细阅读文档后,我可以说该功能尚不存在。我什至
本文实例讲述了PHP实现二叉树深度优先遍历(前序、中序、后序)和广度优先遍历(层次)。分享给大家供大家参考,具体如下: 前言: 深度优先遍历:对每一个可能的分支路径深入到不能再深入为止,而且每个
我是一名优秀的程序员,十分优秀!