将对象列表映射为Hibernate中的辅助表

时间:2018-03-24 14:44:13

标签: java hibernate persistence

我想改变它,以便TypeEn和TypePl成为一个名为Type的类。我不知道如何改变这种结构:

@Entity
@Table(name="place")
class Place{

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;    

    @OneToMany(mappedBy = "place", cascade = CascadeType.ALL)
    private List<TypePl> typePl;

    @OneToMany(mappedBy = "place", cascade = CascadeType.ALL)
    private List<TypeEn> typeEn;
}

TypePl和TypeEn类具有相同的字段:

@Entity
@Table(name = "place_tag_pl")
public class TagPl implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "name")
    private String name;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "place_id")
    private Place place;
}

0 个答案:

没有答案