如何使用Hibernate插入到没有重复行的oracle中?

时间:2016-08-05 06:09:36

标签: java oracle hibernate

我有一些课程电话

public class Calls {
private String Field1;
//and many fields, for example 15
private List<MyModel> models;
}

每分钟我都会得到List of Calls

List<Calls> list = someService.getCallsList();

并尝试将其插入到数据库

    Session session = getSession();
    Transaction tx = session.beginTransaction();

    for(int i=0; i< list.size(); i++) {
        Calls calls = list.get(i);
        session.createSQLQuery(
"INSERT /*+ ignore_row_on_dupkey_index(CALLS,UNIQUE_CALLS_CONSTRAINT) */ " +
         "INTO CALLS(Field1,....,FieldEnd) VALUES(:field1,...,:fieldEnd)")
    .setParameter("field1",calls.getField1()
    //set all params
    .setParameter("fielEnd1",calls.getFieldEnd();
                if ( i % 20 == 0 ) { //20, same as the JDBC batch size
                    //flush a batch of inserts and release memory:
                    session.flush();
                    session.clear();
                }
            }
            tx.commit();
            session.close();
    }

我需要插入行并跳过所有重复:/*+ ignore_row_on_dupkey_index(CALLS,UNIQUE_CALLS_CONSTRAINT) */ /为此我使用SQLQuery

我的问题是:如何在没有SQLQuery的情况下使用hibernate进行此操作?通常是正确实施的。我有15个参数,我不希望它们都注册SQLQuery

1 个答案:

答案 0 :(得分:-1)