views:

71

answers:

1

Let's say I have:

class Unit {
    private TextContainer source;
    private List<TextContainer> targets;
}

Can I annotate class TextContainer in such a way that it works within both relationships? TextContainer must be either source or target.

+2  A: 

You need to annotate the relations with TextContainer in the Unit class. Something like this:

class Unit {

    @ManyToOne(cascade=CascadeType.ALL) 
    private TextContainer source;

    @OneToMany(cascade=CascadeType.ALL) 
    private List<TextContainer> targets;
}
Pascal Thivent