Having these classes:
public class SomeCompositeKey implements Serializable {
private Long objectAId;
private Long objectBId;
private Long objectCId;
}
//lombok annotations~~
@Entity
@Table(name = "objects_assoc")
@IdClass(SomeCompositeKey.class)
public class ObjectsAssocEntity {
@Id
@ManyToOne
@JoinColumn(name = "object_a_id")
private ObjectAEntity objectA;
@Id
@ManyToOne
@JoinColumn(name = "object_b_id")
private ObjectBEntity objectB;
@Id
@ManyToOne
@JoinColumn(name = "object_c_id")
private ObjectCEntity objectC;
}
I'm fetching references of ObjectsAssocEntity members using EntityManager.getReference() and trying to save few entities at once using saveAll method, and each time hibernate executes select to check wheter entity exists or not and then make single insert in case when it not exists.
Is there any possibility to use batch insert in this case? Or should I try to do this e.g with native query?