using spring 3.2.1,
I found that the default flushModeType = Auto causing me issues as im trying to work on the object before persist it.
I tried to set the flushMode to COMMIT, but whenever it happens outside of a @Transactional method, it goes back to AUTO.
I tried set the flushMode as env var, and directly on the entityManager but gets the same behavior. whenever set the flushMode outside of transaction, it has no meaning.
entityManager.setFlushMode(FlushModeType.COMMIT);
System.out.println(entityManager.getFlushMode());
prints ‘AUTO’
updated:
the code been affected out of the auto flushmode:
private void insertImageToDB(String imagePath, Map<String, ImageMetaData> imageNameToMetaData, int numOfImages,
int currentImage) {
try {
ImageDB imageDB = new ImageDB();
imageDB.setGcsFullPath(imagePath);
imageDB.setStatus(PENDING);
setImageMetaData(imagePath, imageNameToMetaData, imageDB); //calling more setters in this method
imagesRepository.save(imageDB); //this clause causing extra persistence. i can solve it locally by removing this, but preffer to work with explicitly 'save()' action in order to under where and when im doing the commit.
logger.debug("processed {}/{} images", currentImage, numOfImages);
} catch (Exception e) {
logger.error("failed to save image {}", imagePath, e);
}
}
Ben Sagi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4