我有一些课程电话
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
答案 0 :(得分:-1)
您可以使用Criteria的Oracle提示,请参阅: https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/Criteria.html#addQueryHint(java.lang.String)