我要执行以下操作:

@Entity
@Table(name="things")
public class Thing
{
    @Id
    private String id;

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    private Set<Thing> alreadyMatchedThings;

    //getters and setters
}

不出所料,这将创建表Things_things,并且由于有时两列都会重复相同的值,所以我真正想要的是将这两列(id和外键)视为复合主键。

不太意外,我收到键“ readyMatchedThings_id”的重复条目“ 1165f4a1-c369-41ea-888c-0e3798deb04f”

我该如何实现?

===============>>#1 票数:0

好吧,我想我可以简单地去:

@Entity
@Table(name="things")
public class Thing
{
    @Id
    private String id;

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinColumn(name="sourcethingid")
    private Set<MatchedThing> matchedThings;

    //getters and setters
}

哪里

@Entity
public class MatchedThings
{
    @Id
    private String id;

    private Thing matchedThing;

    //getters and setters
}

干得好,我。

  ask by user1459955 translate from so

未解决问题?本站智能推荐:

关注微信公众号