@OnetoMany 类调用

发布于 2024-11-01 11:18:17 字数 1909 浏览 4 评论 0原文

我的课程需要一些帮助...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何止钟意 2024-11-08 11:18:17

您要么执行

@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;

第一种情况意味着该实体将是拥有方,即它将拥有外键。

You either do

@Column(name="parent",nullable = true)
@ManyToOne(cascade=CascadeType.ALL)
private OrbitObject OrbitObject;

Or

@Column(name="parent",nullable = true)
@OneToMany(cascade=CascadeType.ALL)
private Set<OrbitObject> OrbitObject;

The first case implies this entity will be the owning side, namely, it will have the foreign key.

半衬遮猫 2024-11-08 11:18:17

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

倦话 2024-11-08 11:18:17

例如,您可以使用 @OneToMany 来引用元素集合

@OneToMany
List<OrbitObject> orbitList;

you can use @OneToMany referring to a collection of elements, for example

@OneToMany
List<OrbitObject> orbitList;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文