嗨,我对播放框架和 JPA 很陌生。我正在创建 Web 应用程序,我需要在应用程序的模型端有 2 个类。当我运行应用程序时出现此错误:非法尝试将非集合映射为 @OneToMany、@ManyToMany 或 @CollectionOfElements:
package models;
import java.util.ArrayList;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import play.db.jpa.Model;
@Entity
public class SubCategory extends Model{
@Column(unique = true)
public String subCatName;
@ManyToOne
public Category category;
public SubCategory(String subCatName,Category category){
this.subCatName=subCatName;
this.category=category;
}
}
package models;
import java.util.ArrayList;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import org.hibernate.engine.Cascade;
import play.db.jpa.Model;
@Entity
public class Category extends Model{
@Column(unique = true)
public String catName;
@OneToMany(mappedBy="category", cascade=CascadeType.ALL)
public ArrayList<SubCategory> allSubCat;
public Category(String catName){
this.catName=catName;
allSubCat=new ArrayList<SubCategory>();
}
}