简体   繁体   English

Ebean中的@OneToMany关系

[英]@OneToMany relation in Ebean

I'm trying to write a system which contains people and applications. 我正在尝试编写一个包含人员和应用程序的系统。 Every person can apply for different applications. 每个人都可以申请不同的申请。

I'm trying to apply a @oneToManyRelation on the person object (when retriving a person from the db, I would like to recive a list with every aplication that they applied for). 我正在尝试在person对象上应用@oneToManyRelation (从数据库中检索一个人时,我想获取他们所申请的每种应用的列表)。

Here is my code: 这是我的代码:

@Entity
@Table(name="t_person")
public class person extends Model {
    @id
    @column(name="PERSON_ID")
    private string ID;

    more properties...

    @OneToMany(targetEntity=application.class, mappedBy="SOLDIER_ID")
    private ArrayList<application> ApplicationList;

    public ArrayList<application> getApplicationList() {
        return ApplicationList;
    }

    public void setApplicationList(ArrayList<application> applicationList) {
        ApplicationList = applicationList;
    }
}

@Entity
@Table(name="T_APPLICATION")
public class application extends Model {
        @Id
        @Column(name="APPLICATION_ID")
        private int Id;

        @ManyToOne
        @JoinColumn(name="PERSON_ID")
        private person Person;
}

I'm using Activator and an Oracle DB. 我正在使用Activator和Oracle DB。 When I retrieve an application I get the person object ok, but when retriving a person, the application list is null. 当我检索一个应用程序时,我得到了好的人员对象,但是当检索一个人时,该应用程序列表为空。

Where am I going wrong? 我要去哪里错了?

Use mappedBy on your annotation for reverse attributes; 在注释中使用mappedBy获取反向属性; it's not the column name you should use here but the name of the attribute on other object. 它不是您应该在此处使用的列名称,而是其他对象上的属性名称。

On Person: 在人:

@OneToMany(mappedBy = "person", fetch = FetchType.EAGER)
ArrayList<Application> applicationList;

On Application: 在应用程序:

@ManyToOne
Person person;

You may need to add @JoinColumn where applicable. 您可能需要在适用的地方添加@JoinColumn As said in comments, fetch = FetchType.EAGER shoudl help too. 如评论中所述, fetch = FetchType.EAGER应提供帮助。

i found the problem. 我发现了问题。 the problem is that applicationList is an ArrayList<> and not a List<>. 问题是applicationList是ArrayList <>而不是List <>。 as soon as i change the ArrayList to a List. 一旦我将ArrayList更改为列表。 it's working. 它正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM