cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP Insert into Hana not possible due to "no subsequent .run allowed, without prior .begin"

Animatron56
Participant
0 Kudos

I am currently writing an application with sap cap which firstly fetches Role collections from the BTP and then inserts them in a Hana Cloud DB when it receives a request via API.

In my local development environment where I use sqlite, everything works fine. However, when I push the code to CF and use Hana Cloud I get the following error: "Error: Transaction is rolled back, no subsequent .run allowed, without prior .begin"

The code looks as follows (Peusdo code)

const response = await fetch('Role-Collections-From-BTP-URL')
const roleCollections = await response.json()

await Promise.all(roleCollections.map(async (role) => {
     const newRC = await addAdditionalInfoToRC(role) 


     await srv.create(RoleCollections).entries(newRC) //Here the error appears
})


...


async function addAdditionalInfoToRC(role) {
 const azureGroupDetails = await srv.read(AzureGroups).where(ID: ID)
 role.azure = azureGroupDetails
return role }

I have another serivce endpoint where I think I do the same and there it also works for Hana, but here it does not work. In this endpoint I also fetch something and then insert it into the hana via a map function.

I have tried googling the error, but have not found anything similar.

Did anyone else face the same issue or knows how to fix it?

Thank you very much !

vansyckel
Advisor
Advisor
0 Kudos

Why is the transaction rolled back? It could very well be that that error only occurs in the deployed version. You'll need to find and fix the root cause of the rollback.

Animatron56
Participant
0 Kudos

vansyckel I dont know why the transaction is rolled back. For me the code looks fine and this makes finding the root cause of the problem very hard. I also tried to do it via additional logging in the db but I found nothing there.

vansyckel
Advisor
Advisor

Hi Benjamin,

You can try to debug with:

cds.db.before('ROLLBACK', async function(req) {
  // break here
})

Accepted Solutions (0)

Answers (0)