I have an Ingestion
class that exposes a single method ingest
. This method processes each section of a passed in form (section 1, section 2, etc, etc).
I have private methods for each section, saving the entity as it processes through. I'm aware that @Transactional
has no effect on private methods, however I do not want to expose these methods but would like to use the functionality that @Transactional
provides.
I'm looking to make sure each section completes in its own Transaction
; I could do this through 'AspectJ' (as other SO answers have suggested) instead of Spring's out the box implementation, but I am trying to avoid due to the system wide changes it would cause.
Any thoughts on another approach?
The pseudo code provided below gives a general idea on the structure of the class:
public Class Ingestion {
// Autowired Repo's
...
...
@Transactional
public void ingest(Form form){
this.processSection1(form);
this.processSection2(form);
this.processSection3(form);
}
@Transactional
private void processSection1(Form form){
// do specific section 1 logic
section1Repo.save(form);
}
@Transactional
private void processSection2(Form form){
// do specific section2 logic
section2Repo.save(form);
}
@Transactional
private void processSection3(Form form){
// do specific section3 logic
section3Repo.save(form);
}
}
=========================================================================
This is not a duplicate question as marked in the comments. I know @Transactional
doesnt work on private methods. My question is more along the lines of 'how do we get around this Spring AOP issue without having to use AspectJ'