I have many table in which i need to insert duplicate record with different primary key. Here are relationships..
@Entity
class A{
@Id
private String USER_ID;
}
@Entity
class B{
@Id
private String id;
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
@JoinColumn(name = "USER_ID")
A a;
}
I need to insert record in B.
I had get related data from tables B. Create new copy to it.. But reference of A is still same. Change it's primary key(which is not auto generated.)
and when call jpa.save(b) method.. it first hit select query and select all field of A then fire insert query.
This select query is extra one. can anyone know how to avoid this?