Correct way to use transactionTemplate for DB transactions

I’m developing a plugin that will create pages in Confluence with given content as well as attachments on those pages via SDK. I couldn’t find suitable examples for this in the Atlassian tutorials. I understand that we should probably use transactionTemplate when using transactional commands but don’t know if I’m using it correctly.

List<AttachmentUpload> uploads = new ArrayList<>();
AttachmentUpload attachmentUpload = new AttachmentUpload(file, filename, mediaType, null, TRUE, FALSE);

// Creating attachment
transactionTemplate.execute(() -> attachmentService.addAttachments(contentId, uploads));

For a large corpus I can see errors like

[confluence.impl.hibernate.ConfluenceHibernateTransactionManager] doRollback Performing rollback. Transactions:
    [PluginReadWriteTx]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT (Session #1865119116)
        [tx-metadata-provider]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly (Session #1610678)
      ->[tx-metadata-provider]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly

Does anyone know what the issue here might be? I think it might be because there are too many attachments rapidly being attached but I don’t know how to debug it.

Also, I’m using the following approach to create a new Page in Confluence. But I’m unable to wrap it in a transactionTemplate and am wondering if it’s necessary

SaveContext suppressPageMod = new DefaultSaveContext.Builder().updateLastModifier(TRUE).suppressEvents(TRUE).build();
contentEntityManager.saveContentEntity(newPage.getEntity(), suppressPageMod);

Thanks in advance!