Closed metkuten closed 4 years ago
You need to explicitly pass the transaction into create
.
const address = await this.addressRepo.create(addressObj, {transaction});
See https://loopback.io/doc/en/lb4/Using-database-transactions.html#perform-operations-in-a-transaction
@raymondfeng : still facing issue, i have implemented transaction as mentioned above. but sometime its returning undefined after calling beginTransaction instead of Promise
getting below error in console. Kindly help on this.
2019-11-15T21:00:52.747Z [founders-mw-dev-699fbb8489-z6k46] error: {"APPLICATION_NAME":"FOUNDERS_SVC","MESSAGE":"uncaughtException: cb is not a function\nTypeError: cb is not a function\n at /u01/foundersplatform/founders-mw/node_modules/loopback-connector/lib/transaction.js:119:5\n at /u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/lib/transaction.js:25:7\n at /u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/mssql/lib/base.js:813:9\n at /u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/mssql/lib/tedious.js:333:11\n at Request.userCallback (/u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/tedious/lib/connection.js:1479:16)\n at Request._this.callback (/u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/tedious/lib/request.js:61:27)\n at Connection.endOfMessageMarkerReceived (/u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/tedious/lib/connection.js:1944:20)\n at Connection.dispatchEvent (/u01/foundersplatform/founders-mw/node_modules/loopback-connector-mssql/node_modules/tedious/lib/connection.js:1012:38)\n at Parser.
Facing issue in loopback 4. Transaction is not working. i am extending repository with DefaultTransactionalRepository.
i am writing below code inside controller.
Issue is, record which i created at line 2 is not getting reverted after line no 3, there is no error in background. also i am getting addressTransaction object back after line no 1. above 3lines are just an example. moto is i want to revert back data that inserted at line no2.
If i execute below code into ms-sql DB its working perfectly fine. record is getting roll back.
BEGIN TRANSACTION INSERT into addresses(ADDRESS_CITY,ADDRESS_STATE) values('123','1234') ROLLBACK
i checked with DBA, look like we are not setting "implicit_transactions on" with above transaction. also connector is not calling beginTransaction or rollback queries back to DB.
select, insert queries are working perfectly fine.
Kindly advice.