我剛開始在Play Framework網絡應用程序中構建我的JPA模式。我對SQL有一個合理的理解,但我是JPA新手,在第一個障礙中我被絆倒了。基本的JPA問題:「無法確定類型爲:java.util.Set」
從Play教程我假設你只是創建你的Java類和JPA/Play會自動爲你創建架構。
所以我要創建兩個模型類,Rankable和標籤之間的多對多關係:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Rankable extends Model {
public String name;
private Set<Tag> tags;
@ManyToMany()
@JoinTable(name = "RANKABLE_TAGS")
public Set<Tag> getTags() {
return tags;
}
@ManyToMany()
@JoinTable(name = "RANKABLE_TAGS")
public void setTags(final Set<Tag> tags) {
this.tags = tags;
}
}
而其他類:
@Entity
public class Tag extends Model {
public String name;
public String description;
private Set<Rankable> rankables;
@ManyToMany(mappedBy = "tags")
public Set<Rankable> getRankables() {
return rankables;
}
@ManyToMany(mappedBy = "tags")
public void setRankables(final Set<Rankable> r) {
rankables = r;
}
}
但我不斷收到以下錯誤:
A JPA error occurred (Unable to build EntityManagerFactory): Could not determine type for: java.util.Set, at table: Rankable, for columns: [org.hibernate.mapping.Column(tags)]
我在做什麼錯?
是什麼模型? – kem 2011-01-25 19:52:55
@kem - [Model](http://www.playframework.org/documentation/api/1.1.1/play/db/jpa/Model.html)是框架的類之一 – 2011-01-26 01:09:30
額外的`}`在你的代碼或只是發佈錯誤? – 2011-01-26 01:12:37