【发布时间】:2017-10-29 15:49:57
【问题描述】:
我正在制定一个计划来整理我的无聊。我最近才开始,所以我还没有开始使用 GUI。该程序在视频/书籍上运行良好,但现在我添加了Game,我得到了queryException。有人知道我做错了什么吗?
错误:
原因:异常 [EclipseLink-6029] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException 异常说明:必须提供引用类。
发生错误的行:
public <E> List<E> getAll(Class<E> eClass){return manager.createQuery(manager.getCriteriaBuilder().createQuery(eClass)).getResultList(); }
不同实体类型调用该行的位置
for (Class eClass: Project.getAllItemTypes())
repos.put(eClass, new Repository(persistenceAdministrator, eClass));
实体类型
public static Class[] getAllItemTypes(){
return new Class[]{Movie.class, TvShow.class, ComedyShow.class, Book.class, Comicbook.class, Manga.class, Game.class};
}
Game 和 Task 的 create-sql
CREATE TABLE Game(
id INT NOT NULL AUTO_INCREMENT,
stateStr VARCHAR(50) NOT NULL,
title VARCHAR(100) NOT NULL,
releaseDate DATE NOT NULL,
gameId INT NULL,
PRIMARY KEY (id),
CONSTRAINT FK_gameId_game
FOREIGN KEY (gameId)
REFERENCES Game (id));
CREATE TABLE Task(
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
completed BOOLEAN NOT NULL,
gameId INT NOT NULL,
PRIMARY KEY (id),
CONSTRAINT FK_gameId_task
FOREIGN KEY (gameId)
REFERENCES Game (id));
游戏类:
@Entity
public class Game extends Item implements Serializable{
@OneToMany
private List<Game> children = new ArrayList<>();
@OneToMany
private List<Task> tasks = new ArrayList<>();
}
物品类别
@MappedSuperclass
public abstract class Item extends IEntity implements Serializable{
@Transient
private State state;
@Column(nullable=false)
private String stateStr;
@Basic(optional = false)
@Column(name = "releaseDate")
@Temporal(TemporalType.DATE)
private Calendar releaseDate;
@Column(nullable=false)
private String title;
IEntity 类
@MappedSuperclass
public abstract class IEntity extends Object implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
【问题讨论】: