我上课需要一些帮助...
package com.it.ese.orbit.entity;
import javax.persistence.*;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: Shahriar Newaz
* Date: 07/03/11
* Time: 10.07
*/
@Entity
@Inheritance(strategy =InheritanceType.JOINED)
public class OrbitObject {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name="id",nullable = false)
private Long id;
@Column(name="Scenario",nullable = false)
private String scenario; // not sure about how to map scenario
@Column(name="code",nullable = true)
private String code;
@Column(name="name",nullable = true)
private String name;
@OneToOne(cascade=CascadeType.ALL)
private Bia bia;
@OneToOne(cascade=CascadeType.ALL)
public Impatti impatti;
@Column(name="parent",nullable = true)
@OneToMany(cascade=CascadeType.ALL)
private OrbitObject OrbitObject;
public Long getId() {
return id;
}
protected void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getScenario() {
return scenario;
}
public void setScenario(String scenario) {
this.scenario = scenario;
}
public String getName() {
return name;
}
public void setName(String name) {
name = name;
}
// LOG
@Override
public String toString(){
return "com.it.ese.orbit.models.OrbitObject["
+ " - name="+name + " - scenario="+scenario +" - id= "+id+"]";
}
}
但是我得到这个错误...
原因:org.hibernate.AnnotationException:非法尝试将非集合映射为@ OneToMany,@ ManyToMany或@CollectionOfElements:com.it.ese.orbit.entity.OrbitObject.OrbitObject
我希望我像同一个类的对象一样创建一个OrbitObject字段...
请帮助!
最佳答案
你要么做
@Column(name="parent",nullable = true)
@ManyToOne(cascade=CascadeType.ALL)
private OrbitObject OrbitObject;
要么
@Column(name="parent",nullable = true)
@OneToMany(cascade=CascadeType.ALL)
private Set<OrbitObject> OrbitObject;
第一种情况意味着该实体将是拥有方,即它将具有外键。