I need to save a list of objects of a table with composite primary key, I am doing as shown below. But I am getting an error Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint violated. But the items in the list are unique, what am I doing wrong.
// Table structure
@Entity
@Table(name="COMP_PRIMARY")
CompPrimaryObj{
@Id
@Column(name="KEY1")
private String key1;
@Id
@Column(name="KEY2")
private Long key2;
}
// code in my service layer
List<CompPrimaryObj> compPrimaryObjList = new ArrayList<CompPrimaryObj>();
CompPrimaryObj obj1 = new CompPrimaryObj();
obj1.setKey1("key1");
obj1.setKey2(11111);
compPrimaryObjList.add(obj1);
CompPrimaryObj obj2 = new CompPrimaryObj();
obj2.setKey1("key2");
obj2.setKey2(222222);
compPrimaryObjList.add(obj2);
for(CompPrimaryObj compPrimaryObj:compPrimaryObjList){
em.persist(compPrimaryObj); // em stands for Entity manger instance
}