Reputation: 437
I have the following scenario:
I have a method (parent method) that is annotated with @Transactional(readOnly = true)
where I fetch some entities. This method will call another method (child method) multiple times (100+) that needs create a person entity and needs the fetched entities for this. This child method has the fetched entities as arguments and is annotated with @Transactional(propagation = Propagation.REQUIRES_NEW)
because I don't want the failure of the creation of one person stop the creation of the others.
What I would like to know is the following:
Upvotes: 0
Views: 399
Reputation: 16430
If all the read only method does is fetching and then passing the object to the other method, you would be better off just using a single write transaction or batched write transactions if you update lots of objects IMO. Can you explain why the child method could fail?
What you are doing is one way of doing "batch jobs". Since you are creating a transaction for every item you are essentially using a so called "chunk size" of 1. This might put a lot of pressure on your database if you have many items to process that are simple to process. Usually it's better to design for a variable chunk size and adapt the chunk size until it fits your needs.
Depending on your ecosystem you could make use of one of the following solutions:
Upvotes: 1