0

我想做以下事情:

@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 和外键)视为复合主键。

不出所料,我收到错误重复条目 '1165f4a1-c369-41ea-888c-0e3798deb04f' for key 'alreadyMatchedThings_id'

我怎样才能做到这一点?

4

1 回答 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
}

干得好,我。

于 2013-04-17T09:01:46.970 回答