我得到以下錯誤:playframework JPA錯誤和DB設計問題
JPA錯誤 發生JPA錯誤(無法建立的EntityManagerFactory):上models.Issue.project @OneToOne或@ManyToOne引用了未知的實體: 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中。
我也有第二個問題。理想情況下,我需要爲每個用戶分配一個數據庫,並且我希望在用戶每次登錄(或註銷)時刪除表的內容,並在用戶登錄時再次填充表(這是因爲存儲在我的數據庫中的信息必須與我連接的服務保持同步)。我應該怎麼做?
我完全沒有線索。請幫幫我。
你說得對。對不起。 – GLF 2012-01-31 08:22:42
@GLF不要對不起。畢竟這是一個問答網站。所以你做的都對,也許別人也可以從中學習;-) – dertoni 2012-01-31 08:49:44
@GLF不要忘記標記這是正確的答案。 – tmbrggmn 2012-01-31 10:38:55