双向@Any关系

时间:2018-12-14 16:43:34

标签: hibernate jpa relationship

我正在尝试实现双向@Any关系,但是遇到了很多绊脚石

public interface Noteable {
    // using this interface to link different classes together that have the ability to attach notes to
    public List<Note> getNotes();
    public void setNotes(List<Note> notes);
}

public class Quote implements Noteable {
    @Id
    private long id;        

    // is there a way to make this a persistable relationship such as
    // @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="owner")
    private List<Note> notes;
}

public class Person implements Noteable {
    @Id
    private long id;

    // similar to Quote
    private List<Note> notes;
}

public class Note {
    @Id
    private long id;

    @Any(metaDef="MyMetaDef", metaColumn=@Column(name="owner_type")
    @JoinColumn("owner_id")
    private Noteable owner;
}

上面的代码将允许我创建新的笔记,附加所有者并保留新的笔记。我还希望能够创建一个新的便笺,将其添加到Quote.notes中,并且当Quote保持不变时,它也将持久化新便笺。

0 个答案:

没有答案