我正在尝试从ADDRESS表向jvald_address表插入3百万条记录。 记录从ADDRESS表插入到jvald_address表中,但在插入300万条记录后,记录将自动从jvald_address表中删除。看起来像hibernate中的QUERY接口有问题。以下是代码段。
public String getaddress()
{
// StatelessSession session = sessionFactory.openStatelessSession();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
/*for ( int i=0; i<100000; i++ ) {*/
/*String del = "delete from jvald_address";
Query query = session.createSQLQuery(del);
query.executeUpdate();*/
System.out.println("BEFORE queryaddress FETCH");
String hql = "insert into jvald_address(JVALD_ADDRESS_KEY,JVALD_BUILDING_NUMBER,JVALD_CONCAT_INDICATOR,JVALD_DELIVERY_POINT_SUFF,JVALD_DEPENDENT_THR_DESC_KEY,JVALD_DEPENDENT_THR_KEY,JVALD_NUM_HOUSEHOLD,JVALD_PO_BOX_NUM,JVALD_POSTCODE_INWARD_OUTWARD_ID,JVALD_SMALL_USER_ORG_INDICATOR,JVALD_ORGANISATION_KEY_ID,JVALD_POSTCODE_TYPE,JVALD_SUB_BUILDING_NAME_KEY_ID,JVALD_BUILDING_NAME_KEY_ID,JVALD_THOROUGHFARE_DESC_KEY_ID,JVALD_THOROUGHFARE_KEY_ID,JVALD_LOCALITY_KEY_ID) select ADDRESS_KEY,BUILDING_NUMBER,CONCATENATION_INDICATOR,DELIVERY_POINT_SUFFIX,DEPENDENT_THOROUGHFARE_DESCRIPTOR_KEY,DEPENDENT_THOROUGHFARE_KEY,NUMBER_OF_HOUSEHOLDS,PO_BOXNUMBER,POSTCODE_OUTWARD_INWARD,SMALL_USER_ORGANISATION_INDICATOR,ORGANISATION_KEY,POSTCODE_TYPE,SUB_BUILDING_NAME_KEY,BUILDING_NAME_KEY,THOROUGHFARE_DESCRIPTOR_KEY,THOROUGHFARE_KEY,LOCALITY_KEY from ADDRESS";
Query queryaddress = session.createSQLQuery(hql);
queryaddress.setFetchSize(100000);
queryaddress.executeUpdate();
tx.commit();
System.out.println("AFTER queryaddress FETCH");
/* if( i % 50 == 0 ) // Same as the JDBC batch size
{
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}*/
//session.close();
return "success";
}