Tree copy question

Hi, there is a tree copy question, I’m not sure that can be solved by hibernate(JPA).
I have a menu tree store in table.I want to be able to copy the tree and have the resulting parentIds refer to the appropriate new ids for the copied values.eg:

   id            name         parentId
---------------------------------------------
   0              tree0           null
   1              tree1           null
   2              tree2             0
   3              tree3             0
   4              tree4             1
   5              tree5             3

Copy result(id is Generated):

   id            name         parentId
---------------------------------------------
   6              tree0           null
   7              tree1           null
   8              tree2             6
   9              tree3             6
   10             tree4             7
   11             tree5             9

My entity:

@Id
@GenericGenerator(name = "jpa-uuid", strategy = "uuid2")
@GeneratedValue(generator = "jpa-uuid")
@Column(name = "id", nullable = false, length = 40)
private String id;

@NotNull
@Size(max = 60)
@ApiModelProperty(value = "name", required = true)
@Column(name = "name", length = 60, nullable = false)
private String name;

@ManyToOne
private Menu parent;

So how can I do?

Try using Session.replicate and see if it works for your use case.