I use hibernate-jpa-2.1-api. And I need some functionality.
I parse a file every minute and insert data into MSSQL DB. I need to skip duplicate rows. For example at 12:00 I've got in my file 300 rows. I parse every of them and insert 300 rows. After one minute (12:01) my file contains 500 rows. I parse it and I want to insert only the 200 new rows and not the old 300 rows.
In the old realization of the program I used SQL insert and did not use ORM.
Here is my old SQL query:
insert /*+ ignore_row_on_dupkey_index(avaya_cm_cdr, i_avaya_cm_cdr_nodub) */ into avaya_cm_cdr(acmcdr_id, cdrdate, cdrtime, secdur, condcode, attdconsole, codeused, outcrtid, codedial, dialednum, intrkcode, incrtid, callingnum, vdn, bcc, ppm, acctcode, authcode) values(seq_acmcdr_id.nextval, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
And here is my new insert with ORM:
em = Persistence.createEntityManagerFactory("COLIBRI").createEntityManager();
public void insertAVAYAcmCDRs(List<AvayaCmCdr> cdrList) {
em.getTransaction().begin();
for (AvayaCmCdr aCdrList : cdrList) {
em.persist(aCdrList);
}
em.getTransaction().commit();
}
How can I use the analog to the function ignore_row_on_dupkey_index with ORM?
p.s. In the old realization I've used an Oracle DB.