I have a class, Location. Location contains a List of BorderPoint objects, but it can be a HUGE list (20,000 is not impossible). The tables for this are LOCATION and BORDERPOINT.
I initially populate Location via an import from an ESRI Shapefile. Here’s a code snip:
try {
while (featureIterator.hasNext()) {
Location location = new Location();
SimpleFeatureImpl feature = (SimpleFeatureImpl) featureIterator.next();
// set the information in location based on stuff in the feature, lets me clean up this
// method a bit
setLocationInfo(location, feature);
List<BorderPoint> borderPointList = getBorderPoints(feature, location);
//saveBorderPoints(location, feature);
location.setBorderPointList(borderPointList);
try {
locationRepository.persist(location);
} catch (RepositoryException e) {
throw new ServiceException("processShapefile() threw RepositoryException", e);
}
}
} finally {
featureIterator.close();
}
Since there are so many BorderPoint objects in the List, but I am only saving them by calling persist on the Location object, can I automatically set some sort of batch size for persisting the BorderPoints?
I don’t know OpenJPA, but I have used Hibernate a lot. You probably have to control the transaction size yourself. If you change the code a little this should be easy: