Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The inserted data is lost #1171

Open
scf18857887860 opened this issue Sep 6, 2024 · 0 comments
Open

The inserted data is lost #1171

scf18857887860 opened this issue Sep 6, 2024 · 0 comments
Labels
question Further information is requested

Comments

@scf18857887860
Copy link

scf18857887860 commented Sep 6, 2024

Describe the bug
In my framework, which uses MyBatis-Flex, data is inserted within the same transaction, and the insertion returns successfully. The data can also be queried within the transaction. However, after the request ends, the data is lost when queried in a subsequent request, even though other data within the same transaction remains intact.

To Reproduce
Provide a sample code that reproduces the error.

TransactionManager.execTransaction(() -> {
            try {
                    List<MESPay> addPayList = processMarkingPayBO.getAddPayList();
                    log.info("营销SDK-addPayList,size={}", addPayList.size());
                    if (CollectionUtils.isNotEmpty(addPayList)) {
                        int count = 0;
                        for (MESPay mesPay : addPayList) {
                            count += mesPayDao.create(mesPay);
                        }
                        log.info("营销SDK-addPayList,count={}", count);
                        List<MESPay> mesPays = 
            `mesPayDao.queryByOrderKeyIgnoreLogicDelete(addPayList.get(0).getEdgeOrderKey());`
                        log.info("营销SDK-orderKey,mesPays={}", JSONObject.toJSONString(mesPays));
                    }
                    if (CollectionUtils.isNotEmpty(updatePayList)) {
                        updatePayList.forEach(mesPayDao::update);
                    }
            } catch (Exception e) {
                log.error("error happened.", e);
                throw new BusinessException(ErrorCode.FAILED_ADD_PAY_PAY_EXIST, "保存营销活动失败");
            }
            return 1;
        });
  public class TransactionManager {
      public static <TT> TT execTransaction(Supplier<TT> supplier) {
          boolean needLock = DatabaseHelper.databaseType() == DatabaseType.SQLITE;
  
          if (needLock) {
              synchronized (SynchronizedBaseDao.class) {
                  return Db.txWithResult(supplier);
              }
          } else {
              return Db.txWithResult(supplier);
          }
      }
  }

Expected behavior

The data was inserted successfully, and it can also be queried.​⬤

Logs
image

Environment (please complete the following information):

  • OS: [Windows 7]
  • CPU architecture: [x86_64, intel]
  • sqlite-jdbc version [3.39.3.0]

Additional context

@gotson gotson added question Further information is requested and removed triage labels Sep 9, 2024
@gotson gotson changed the title The inserted data is lost. The inserted data is lost Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants