I have some code to insert a collection of one type of objects (only one table is related). Because the size of the collection is very big, I need to flush the session sometimes for not causing OutOfMemory problem. Thus, there is session.flush() and session.clear() to do this.
However, this doesn't work because I have <generator class="hilo">. Then the insert() in class AbstractEntityPersister execute this:
...
else {
// For the case of dynamic-insert="false", use the static SQL
for ( int j = 0; j < span; j++ ) {
insert( id, fields, getPropertyInsertability(), j, getSQLInsertStrings()[j], object, session );
}
...
Then, this line of called
final boolean useBatch = j == 0 && !callable;
...
if ( useBatch ) {
session.getBatcher().addToBatch( 1 );
}
Since span is always 1 and j is always 0, no insertion is executed. This happens before I set "hibernate.jdbc.batch_size".
After I set the property, there is still no improvement. It failed at updateOrInsert() in AbstractEntityPersister -
...
else {
isRowToUpdate = update( id, fields, oldFields, rowId, includeProperty, j, oldVersion, object, sql, session );
}
if ( !isRowToUpdate && !isAllNull( fields, j ) ) {
insert( id, fields, getPropertyInsertability(), j, getSQLInsertStrings()[j], object, session );
}
...
The reason is isRowToUpdate always returns true, then no actual insert gets executed.
Is there a solution for this case?
|