我收到以下错误:
JPA错误 发生JPA错误(无法构建EntityManagerFactory):模型上的@OneToOne或@ManyToOne.Issue.project引用未知实体:models.Project
在这里你可以看到我的实体:
package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;
import models.Issue;
import models.Component;
public class Project extends Model{
public String self;
@Id
public String key;
@OneToMany (mappedBy="Project", cascade=CascadeType.ALL)
public List<Component> components;
@OneToMany (mappedBy="Project", cascade=CascadeType.ALL)
public List<Issue> issues;
public Project(String self, String key) {
this.self = self;
this.key = key;
this.components = new ArrayList<Component>();
this.issues = new ArrayList<Issue>();
}
public Project addComponent(String self, int component_id, String name, int issuecount) {
Component newComponent = new Component(self, component_id, name, issuecount, this);
this.components.add(newComponent);
return this;
}
public Project addIssue(Date created, Date updated, String self, String key,
String type, Status status) {
Issue newIssue = new Issue(created, updated, self, key, type, status, this);
this.issues.add(newIssue);
return this;
}
}
这是另一个
package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;
import models.Project;
import models.Status;
import models.Component;
@Entity
public class Issue extends Model {
@Id
public String key;
public Date created;
public Date updated;
public String self;
public String type;
@ManyToOne
public Status status;
@ManyToOne
public Project project;
@OneToMany
public List<Component> components;
public Issue(Date created, Date updated, String self, String key,
String type, Status status, Project project ) {
this.created = created;
this.updated = updated;
this.self = self;
this.key = key;
this.status = status;
this.type = type;
this.project=project;
this.components=new ArrayList<Component>();
}
public Issue addComponent(Component component) {
this.components.add(component);
return this;
}
}
我正在使用Play 1.2.4和Eclipse。现在我的数据库在mem。
我还有第二个问题。理想情况下,我需要每个用户都有一个数据库,我希望每次用户登录(或注销)时删除表的内容,并在用户登录时再次填充表(这是因为存储在我的数据库中的信息必须与我正在连接的服务保持同步。我该怎么办?
我完全不知道。请帮帮我。
答案 0 :(得分:5)
public class Project extends Model
缺少@Entity
注释
答案 1 :(得分:4)
“mappedBy”应引用另一个实体中属性为“project”而不是“Project”的属性。