我有实体:
@Data
@Entity
@Table(name = "USERS")
public class User{
@Id
@Column(name = "GUID", nullable = false)
private String guid;
@OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = LAZY)
private List<Role> roles;
@OneToMany(mappedBy = "user", fetch = LAZY, cascade = {CascadeType.ALL})
private List<Person> persons;
我需要克隆此实体。我是这样的:
usersRepository.detach(user);
但是由于roles
,我无法获得persons
和LAZY
。我使用hack:
user.getRoles().size();
user.getPersons().size();
usersRepository.detach(user);
但是我不喜欢它。我可以简化它吗?