I have two tables in database having one to many relationship. while I fetch the table User, I want to copy the data in the User (with the data related to Vehicle) to another object UserDuplicate (and VehicleDuplicate). I tried using BeanUtils.copyProperties but the nested references still refer to old object. I want to know what is the way to copy the nested objects. Thanks.
import java.util.Set;
public class User {
private Set<Vehicle> vehs = new HasHSet();
public Set<Vehicle> getVehs() {
return vehs;
}
public void setVehs(Set<Vehicle> vehs) {
this.vehs = vehs;
}
}
class Vehicle {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
class UserDuplicate {
private Set<VehicleDuplicate> vehDup=new HasHSet();
public Set<VehicleDuplicate> getVehDup() {
return vehDup;
}
public void setVehDup(Set<VehicleDuplicate> vehDup) {
this.vehDup = vehDup;
}
}
class VehicleDuplicate {
private UserDuplicate userDup;
public UserDuplicate getUserDup() {
return userDup;
}
public void setUserDup(UserDuplicate userDup) {
this.userDup = userDup;
}
}