I'm having some issues while trying to call a stored procedure from the code (not sure if it helps but it's basically some selects and inserts).
This is what I have so far:
@Component
@EnableTransactionManagement
public class Inserter {
@Transactional(propagation = Propagation.REQUIRED)
public void saveAndCommit(Mapper mapper) {
saveAll(...)
...
softDeletes(mapper, this.containerRepository);
}
private <T, N> void saveAll(JpaRepository<T, N> repository, List<T> entityList) {
if (entityList != null && !entityList.isEmpty()) {
repository.saveAll(entityList);
}
}
private void softDeletes(Mapper mapper, ContainerRepository containerRepository) {
...
}
}
And what I have in softDeletes is a few stored procedure calls like this:
@Modifying
@Query(value = "EXEC SP_Soft_Deletes '...', '...', :state_container_id, :parent_id, :transaction_id, '...', :last_modification", nativeQuery = true)
void generateSoftDeletes(
@Param("...") String ...,
@Param("...") String ...,
@Param("...") String ...,
@Param("last_modification") LocalDateTime last_modification
);
When softDeletes is called, I get the following exception:
Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query
Apparently, saveAndCommit is not creating one transaction for all those methods but I'm not sure why. Any ideas?
Thank you!