Hibernate uuid relational generator injection
Let's say I have the following objects:
@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
}
and
@Entity
public class B {
@Type(type = "pg-uuid")
private UUID aId;
// other fields + getter and setter
}
While creating an object A
(saving with JPA) that contains a list B
, is there a way to use A uuid generator
to populate the field aId
in B
? Or do I need to generate a uuid using UUID.randomUUID()
in java and then create objects A/B
?
+3
source to share
No one has answered this question yet
Check out similar questions: