开发者

@OnetoMany class call

i need some help for my开发者_JAVA技巧 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!


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.


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


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

@OneToMany
List<OrbitObject> orbitList;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜