Hibernate uuid生成器关系插入

时间:2017-04-07 10:26:58

标签: java hibernate uuid

我们说我有以下实体:

@Entity
public class A {

    @Id
    @Type(type = "pg-uuid")
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    private UUID id;

    @OneToMany
    private List<B> bs;

    // other fields + getter and setter
}

@Entity
public class B {

    @Type(type = "pg-uuid")
    private UUID aId;

    // other fields + getter and setter
}

在创建包含A列表的实体B(使用JPA保存)期间,有没有办法使用A's uuid generator填充aId字段B?或者我是否需要在java中使用UUID.randomUUID()生成uuid,然后创建A/B个实体?

0 个答案:

没有答案