@OnetoMany 类调用
我的课程需要一些帮助...
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 字段,就像同一类的对象... 请帮忙!
i need some help for my class...
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+"]";
}
}
But i get thi error...
Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.it.ese.orbit.entity.OrbitObject.OrbitObject
I wish i create an OrbitObject field as like an object of the same class...
Help please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要么执行
要么
第一种情况意味着该实体将是拥有方,即它将拥有外键。
You either do
Or
The first case implies this entity will be the owning side, namely, it will have the foreign key.
OneToMany 意味着 OrbitObject 有许多 OrbitObject 子级,但事实并非如此,因为 OrbitObject 属性不是集合。
您必须将其转换为 ManyToOne
OneToMany means that OrbitObject has many OrbitObject children, which is not true because the OrbitObject property is not a collection.
You must convert it to a ManyToOne
例如,您可以使用 @OneToMany 来引用元素集合
you can use @OneToMany referring to a collection of elements, for example