Я вставляю Список, повторяя для возврата дубликатов данных.
Но я хочу вставить этот список, используя ...
save(Iterable<S> entities)
и также возвращать дубликаты.
Пожалуйста, посмотрите на мои коды так, как я хочу
@Entity
@Table(name="contact")
public class ContactInfo {
@Id
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@Column(name = "contact", unique = true)
private String contact;
public ContactInfo(String name, String contact){
name=name;
contact=contact;
}
}
public interface ContactInfoRepo extends CrudRepository<ContactInfo, Long>{
}
@Service
@Transactional
public class ContactInfoService {
@Autowired
private ContactInfoRepo contactInfoRepo;
//Demo Contact List
public List<ContactInfo> demoList(){
List<ContactInfo> list=new ArrayList<>();
list.add(new ContactInfo("John","88065600"));
list.add(new ContactInfo("Adnan","99821545"));
//In this list, duplicate contact is: 88065600
list.add(new ContactInfo("Tom","88065600"));
list.add(new ContactInfo("ADSIDDIK","+8801942652579"));
return list;
}
//I'm saving List and finding duplicates as following code
public void saveList(){
List<ContactInfo> list=demoList();
for(ContactInfo c:list){
try{
contactInfoRepo.save(c);
}catch (DataIntegrityViolationException e) {
//Getting Duplicate
}catch (Exception e) {
//Any Other error
}
}
}
//But I want like that and get duplicate also....
public void saveContactList(){
List<ContactInfo> list=demoList();
contactInfoRepo.save(list);// as this is : save(Iterable<S> entities)
}
}
Можно ли получить дубликаты данных следующим способом?
saveContactList();
, пожалуйста, помогите
Спасибо