我试图使用JPA映射递归关系。我不知道为什么我在@OneToMany线上出现了一些错误。 这是一个代码示例:
@Entity
public class RecursiveType implements Serializable {
private static final long serialVersionUID = -2459343636539882731L;
@Id
public int id;
@OneToMany(mappedBy="rec1", cascade=CascadeType.PERSIST) //here is where I get the errors
public RecursiveType rec1;
public Map<String, Map<RecursiveType, List<Map<RecursiveType, List<InnerTypes>>>>> rec2;
//getters and setters
}
persistence.xml
档
<class>pt.ptinovacao.persistencetester.model.RecursiveType</class>
我有几个错误,例如:&#34;目标实体未定义&#34;和#34;集合映射的属性类型必须是java.util.Collection ...&#34; 为什么会这样?
答案 0 :(得分:0)
我已修复它,我只是更改了注释和关系类型
@Entity
public class RecursiveType implements Serializable {
private static final long serialVersionUID = -2459343636539882731L;
@Id
public int id;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="REC1_ID", referencedColumnName="ID")
public RecursiveType rec1;
public Map<String, Map<RecursiveType, List<Map<RecursiveType, List<InnerTypes>>>>> rec2; //I really don't need to try and map this xD
//getters and setters
}