当前位置: 首页 > 知识库问答 >
问题:

我想要更新实体,但data整体性违反异常:无法执行语句SQL[n/a];约束SGB。C_PR_PK]发生

汤英豪
2023-03-14

实体

@Entity
@Table(name = "v_CUSTOMER", uniqueConstraints = {@UniqueConstraint(columnNames = {"accno", "radif"})})
@SequenceGenerator(
        name = "sgb.CUSTOMER_SEQ",
        sequenceName = "sgb.CUSTOMER_SEQ",
        allocationSize = 1
)
@Getter
@Setter
@ToString
@FieldNameConstants
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sgb.CUSTOMER_SEQ")
    @Column(name = "NEWLAB_CHRONO", nullable = true, insertable = true, updatable = true, precision = 0)
    @CobolType(numeric = true,nullable = true)
    private Integer newlabChrono;

    @Basic
    @Column(name = "ACCNO", nullable = false, insertable = true, updatable = true, length = 10)
    @CobolType(numeric = true)
    private String accno;

    @Basic
    @Column(name = "ROW", nullable = false, insertable = true, updatable = true, length = 2)
    @CobolType(numeric = true)
    private String row;

    @Basic
    @Column(name = "SHAKHS", nullable = true, insertable = true, updatable = true, length = 1)
    @CobolType(numeric = true)
    private String shakhs;

    @Basic
    @Column(name = "TAR_GAR", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true)
    private String tarGar;

    @Basic
    @Column(name = "ID_ALT1", nullable = true, insertable = true, updatable = true, length = 12)
    @CobolType(numeric = true)
    private String idAlt1;

    @Basic
    @Column(name = "ID_ALT2", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true)
    private String idAlt2;

    @Basic
    @Column(name = "ID_ALT3", nullable = true, insertable = true, updatable = true, length = 3)
    @CobolType(numeric = true)
    private String idAlt3;

    @Basic
    @Column(name = "MELLI_ALT", nullable = true, insertable = true, updatable = true, length = 12)
    @CobolType(numeric = true)
    private String melliAlt;

    @Basic
    @Column(name = "BRANCH_ID", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true, nullable = true)
    private String branchId;

    @Basic
    @Column(name = "BRANCH", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true, nullable = true)
    private String branch;

    @Basic
    @Column(name = "REGION", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true, nullable = true)
    private String region;

    @Basic
    @Column(name = "SITE", nullable = true, insertable = true, updatable = true, length = 2)
    @CobolType(numeric = true, nullable = true)
    private String site;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Customer that = (Customer) o;
        return Objects.equals(accno, that.accno) &&
                Objects.equals(row, that.row);
    }

    @Override
    public int hashCode() {
        return Objects.hash(accno, row);
    }
}

@Entity
@Table(name = "v_CUSTOMER_PERSON")
@SequenceGenerator(
        name = "CUSTOMER_PERSON_SEQ",
        sequenceName = "CUSTOMER_PERSON_SEQ",
        allocationSize = 1
)
@Getter
@Setter
@ToString
@FieldNameConstants
public class CustomerPerson {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUSTOMER_PERSON_SEQ")
    @Column(name = "NEWLAB_CHRONO", nullable = true, insertable = true, updatable = true, precision = 0)
    @CobolType(numeric = true, nullable = true)
    private Integer newlabChrono;

    @Basic
    @Column(name = "ACCNO", nullable = false, insertable = true, updatable = true, length = 10)
    @CobolType(numeric = true)
    private String accno;

    @Basic
    @Column(name = "ROW", nullable = false, insertable = true, updatable = true, length = 2)
    @CobolType(numeric = true)
    private String row;

    @Basic
    @Column(name = "SHAKHS", nullable = true, insertable = true, updatable = true, length = 1)
    @CobolType(numeric = true)
    private String shakhs;

    @Basic
    @Column(name = "TAR_GAR", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true)
    private String tarGar;

    @Basic
    @Column(name = "SH_NO", nullable = true, insertable = true, updatable = true, length = 12)
    @CobolType(numeric = true)
    private String shNo;

    @Basic
    @Column(name = "BIRTH_DATE", nullable = true, insertable = true, updatable = true, length = 6)
    @CobolType(numeric = true)
    private String birthDate;

    @Basic
    @Column(name = "MAH_COD", nullable = true, insertable = true, updatable = true, length = 3)
    @CobolType(numeric = true)
    private String mahCod;

    @Basic
    @Column(name = "COD_ME", nullable = true, insertable = true, updatable = true, length = 12)
    @CobolType(numeric = true)
    private String codMe;

    @Basic
    @Column(name = "GRP1", nullable = true, insertable = true, updatable = true, length = 3)
    @CobolType(numeric = true)
    private String grp1;

    @Basic
    @Column(name = "BIL1", nullable = true, insertable = true, updatable = true, length = 1)
    @CobolType(numeric = true)
    private String bil1;

    @Basic
    @Column(name = "DUP1", nullable = true, insertable = true, updatable = true, length = 1)
    @CobolType(numeric = true)
    private String dup1;

    @Basic
    @Column(name = "NAME1", nullable = true, insertable = true, updatable = true, length = 60)
    @CobolType(numeric = false)
    private String name1;

    @Basic
    @Column(name = "FAMILI1", nullable = true, insertable = true, updatable = true, length = 80)
    @CobolType(numeric = false)
    private String famili1;

    @Basic
    @Column(name = "PERSON1", nullable = true, insertable = true, updatable = true, length = 1)
    @CobolType(numeric = true)
    private String person1;

    @Basic
    @Column(name = "FATHER", nullable = true, insertable = true, updatable = true, length = 60)
    @CobolType(numeric = false)
    private String father;

    @Basic
    @Column(name = "HOZE", nullable = true, insertable = true, updatable = true, length = 2)
    @CobolType(numeric = true)
    private String hoze;

    @Basic
    @Column(name = "CITY1", nullable = true, insertable = true, updatable = true, length = 40)
    @CobolType(numeric = false)
    private String city1;

    @Basic
    @Column(name = "TEL1", nullable = true, insertable = true, updatable = true, length = 13)
    @CobolType(numeric = true)
    private String tel1;

    @Basic
    @Column(name = "POST1", nullable = true, insertable = true, updatable = true, length = 10)
    @CobolType(numeric = true)
    private String post1;

    @Basic
    @Column(name = "ADDRS1", nullable = true, insertable = true, updatable = true, length = 160)
    @CobolType(numeric = false)
    private String addrs1;

    @Basic
    @Column(name = "E_MAIL", nullable = true, insertable = true, updatable = true, length = 40)
    @CobolType(numeric = false)
    private String eMail;

    @Basic
    @Column(name = "FAX1", nullable = true, insertable = true, updatable = true, length = 13)
    @CobolType(numeric = true)
    private String fax1;

    //other fields...
    
    @Transient
    private Integer isForeign;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CustomerPerson that = (CustomerPerson) o;
        return Objects.equals(accno, that.accno) &&
                Objects.equals(row, that.row);
    }

    @Override
    public int hashCode() {
        return Objects.hash(accno, row);
    }
}

此服务已在@Transactional外部服务中调用

@Service
@RequiredArgsConstructor
public class CustomerService {

    @Value("${range.trackingCodeThreadLocalKey}")
    private String trackingCodeKey;
    @Value("${customer.sync.isNewRecord}")
    private String isNewRecordKey;
    private static final Logger log = LoggerFactory.getLogger(CustomerService.class);

    private final CustomerRepository customerRepository;
    private final CustomerPersonRepository customerPersonRepository;
    private final CustomerCompanyRepository customerCompanyRepository;
    private final AccountMapRepository accountMapRepository;
    private final AccountTypeMapRepository accountTypeMapRepository;
    private final CustomerMapper customerMapper;
    private final CompositeCustomerMapper compositeCustomerMapper;
    private final RangeService rangeService;
    private final ThreadLocalUtil threadLocalUtil;

    public String syncAccount(Long newAccountNumber, CustomerAccountResponseDto galaxyData) {
        Optional<AccountMapEntity> optAccountMapEntity = accountMapRepository.findByNewAccountNo(newAccountNumber);
        CustomerDto customerData = new CustomerDto();
        List<CustomerPerson> customerPersonList = null;
        List<Customer> customers = null;
        CustomerCompany customerCompany = null;
        CustomerDto mappedCompositeCustomerPersons;
        boolean updateRecord = false;

        if (optAccountMapEntity.isPresent()) {
            customerData = getCustomerData(optAccountMapEntity.get());
        }

        String legacyAccountNumber = getLegacyAccountNumber(customerData, galaxyData);
        legacyAccountNumber = StringUtil.addLeftLeadingZero(legacyAccountNumber, Constants.Legacy_ACCOUNTNO_MAX);
        log.info("######legacyAccountNumber. {}", legacyAccountNumber);

        if (CustomerUtil.isCompositePerson(galaxyData)) {
            Customer zeroRowCustomer = null;
            CustomerPerson zeroRowCustomerPerson = null;


            if (!ObjectUtils.isEmpty(customerData.getCustomerList()) &&
                    !ObjectUtils.isEmpty(customerData.getCustomerPersonList()) &&
                    customerData.getCustomerList().stream().findFirst().isPresent() &&
                    customerData.getCustomerPersonList().stream().findFirst().isPresent()) {
                updateRecord = true;
                mappedCompositeCustomerPersons = compositeCustomerMapper.compositeInquiryToCustomerDto(galaxyData, customerData);

                if (mappedCompositeCustomerPersons.getCustomerList().stream().findFirst().isPresent())
                    zeroRowCustomer = compositeCustomerMapper.toZeroRowCustomer(galaxyData, mappedCompositeCustomerPersons.getCustomerList().stream().findFirst().get());

                if (mappedCompositeCustomerPersons.getCustomerPersonList().stream().findFirst().isPresent())
                    zeroRowCustomerPerson = compositeCustomerMapper.toZeroRowCustomerPeson(galaxyData, mappedCompositeCustomerPersons.getCustomerPersonList().stream().findFirst().get(), mappedCompositeCustomerPersons.getCustomerPersonList());

                mappedCompositeCustomerPersons.getCustomerList().set(0, zeroRowCustomer);
                mappedCompositeCustomerPersons.getCustomerPersonList().set(0, zeroRowCustomerPerson);

            } else {
                zeroRowCustomer = compositeCustomerMapper.toZeroRowCustomer(galaxyData, new Customer());
                mappedCompositeCustomerPersons = compositeCustomerMapper.compositeInquiryToCustomerDto(galaxyData, null);
                zeroRowCustomerPerson = compositeCustomerMapper.toZeroRowCustomerPeson(galaxyData, new CustomerPerson(), mappedCompositeCustomerPersons.getCustomerPersonList());
                mappedCompositeCustomerPersons.getCustomerList().add(0, zeroRowCustomer);
                mappedCompositeCustomerPersons.getCustomerPersonList().add(0, zeroRowCustomerPerson);
            }

            customers = mappedCompositeCustomerPersons.getCustomerList();
            customerPersonList = mappedCompositeCustomerPersons.getCustomerPersonList();


            if (!ObjectUtils.isEmpty(customers)) {
                for (Customer customer : customers) {
                    customer.setAccno(legacyAccountNumber);
                }
            }
            if (!ObjectUtils.isEmpty(customerPersonList)) {
                for (CustomerPerson customerPerson : customerPersonList) {
                    customerPerson.setAccno(legacyAccountNumber);
                }
            }


        } else if (CustomerUtil.isLegalPerson(galaxyData)) {

            if (!ObjectUtils.isEmpty(customerData.getCustomerList()) &&
                    !ObjectUtils.isEmpty(customerData.getCustomerPersonList()) &&
                    !ObjectUtils.isEmpty(customerData.getCustomerCompany())) {
                updateRecord = true;
                customerPersonList = customerMapper.realPersonToCustomerPersonList(galaxyData, customerData.getCustomerPersonList());
                customerCompany = customerMapper.legalPersonToCustomerCompany(galaxyData, customerData.getCustomerCompany());
                customers = customerMapper.accountToCustomer(galaxyData, customerData.getCustomerList(), customerData.getCustomerPersonList(), customerCompany);

            } else {
                customers = customerMapper.accountToCustomer(galaxyData, new ArrayList<>(), new ArrayList<>(), new CustomerCompany());
                customerPersonList = customerMapper.realPersonToCustomerPersonList(galaxyData, new ArrayList<>());
                customerCompany = customerMapper.legalPersonToCustomerCompany(galaxyData, new CustomerCompany());
            }


            if (!ObjectUtils.isEmpty(customers)) {
                for (Customer customer : customers) {
                    customer.setAccno(legacyAccountNumber);
                }
            }
            if (!ObjectUtils.isEmpty(customerPersonList)) {
                for (CustomerPerson customerPerson : customerPersonList) {
                    customerPerson.setAccno(legacyAccountNumber);
                }
            }
            if (!ObjectUtils.isEmpty(customerCompany)) {
                customerCompany.setAccno(legacyAccountNumber);
            }


        } else if (CustomerUtil.isRealPerson(galaxyData)) {

            if (!ObjectUtils.isEmpty(customerData.getCustomerList()) &&
                    !ObjectUtils.isEmpty(customerData.getCustomerPersonList())) {
                updateRecord = true;
                customerPersonList = customerMapper.realPersonToCustomerPersonList(galaxyData, customerData.getCustomerPersonList());
                customers = customerMapper.accountToCustomer(galaxyData, customerData.getCustomerList(), customerData.getCustomerPersonList(), null);

            } else {
                customers = customerMapper.accountToCustomer(galaxyData, new ArrayList<>(), new ArrayList<>(), null);
                customerPersonList = customerMapper.realPersonToCustomerPersonList(galaxyData, new ArrayList<>());
            }

            if (!ObjectUtils.isEmpty(customers)) {
                for (Customer customer : customers) {
                    customer.setAccno(legacyAccountNumber);
                }
            }
            if (!ObjectUtils.isEmpty(customerPersonList)) {
                for (CustomerPerson customerPerson : customerPersonList) {
                    customerPerson.setAccno(legacyAccountNumber);
                }
            }
        }

        if (!ObjectUtils.isEmpty(threadLocalUtil.getKey(isNewRecordKey)) && (Boolean) threadLocalUtil.getKey(isNewRecordKey))// todo it seems shoule be !isEmpty
            saveAccountMap(newAccountNumber.toString(), legacyAccountNumber);

        saveCustomers(updateRecord, customers, customerPersonList, customerCompany);
        return legacyAccountNumber;
    }

    public void saveAccountMap(String newAccountNumber, String legacyAccountNumber) {
        AccountMapEntity accountMapEntity = new AccountMapEntity();
        accountMapEntity.setNewAccountNo(Long.valueOf(newAccountNumber));
        accountMapEntity.setLegacyAccountNo(Long.valueOf(legacyAccountNumber));
        boolean ifExist = accountMapRepository.existsByNewAccountNoOrLegacyAccountNo(Long.valueOf(newAccountNumber), Long.valueOf(legacyAccountNumber));
        if (!ifExist) accountMapRepository.saveAndFlush(accountMapEntity);
    }


    //todo check below for save and flush of list
    public void saveCustomers(Boolean updateRecord, List<Customer> customers, List<CustomerPerson> customerPersonList, CustomerCompany customerCompany) {
        if (!ObjectUtils.isEmpty(updateRecord) && !ObjectUtils.isEmpty(customers) && !ObjectUtils.isEmpty(customerPersonList)) {

            if (!updateRecord) {
                customerRepository.saveAll(customers);
                customerRepository.flush();
                customerPersonRepository.saveAll(customerPersonList);
                customerPersonRepository.flush();
            } else {
                for (Customer customer : customers) {
                    Optional<Customer> optCustomerById = customerRepository.findById(customer.getNewlabChrono());
                    if (optCustomerById.isPresent()) {
                        Customer customer1 = optCustomerById.get();
                        BeanUtils.copyProperties(customer, customer1);
                        boolean equals = customer1.equals(customer);
                        System.out.println(equals);
                        String s = customer1.toString();
                        customerRepository.saveAndFlush(customer1);
                        log.info("customer updated");
                    }
                }

                 for (CustomerPerson customerPerson : customerPersonList) {
                    CustomerPerson cpSaved = customerPersonRepository.findCustomerPersonByNewlabChrono(customerPerson.getNewlabChrono());
                    BeanUtils.copyProperties(customerPerson, cpSaved);
                    boolean equals = cpSaved.equals(customerPerson);
                    System.out.println(equals);
// ###################
                    customerPersonRepository.saveAndFlush(cpSaved); //Error occurs here
// ###################
                    log.info("customer person updated");
                } 

            }
            if (customerCompany != null)
                customerCompanyRepository.saveAndFlush(customerCompany);

        }
    }

    public CustomerDto getCustomerData(AccountMapEntity accountMapEntity) {
        List<Customer> customerByAccno = customerRepository.findAllByAccountNumber(String.valueOf(accountMapEntity.getLegacyAccountNo()));
        List<CustomerPerson> customerPersonByAccno = customerPersonRepository.findAllByAccountNumber(String.valueOf(accountMapEntity.getLegacyAccountNo()));
        CustomerCompany customerCompanyByAccno = customerCompanyRepository.findByAccountNumber(String.valueOf(accountMapEntity.getLegacyAccountNo()));

        CustomerDto customerDto = new CustomerDto();
        customerDto.setCustomerList(customerByAccno);
        customerDto.setCustomerPersonList(customerPersonByAccno);
        customerDto.setCustomerCompany(customerCompanyByAccno);
        return customerDto;
    }


    private String getLegacyAccountNumber(CustomerDto customerData, CustomerAccountResponseDto galaxyData) {
        String legacyAccountNumber = null;
        if (!ObjectUtils.isEmpty(customerData) && !ObjectUtils.isEmpty(customerData.getCustomerList())) {
            Optional<Customer> optCustomer = customerData.getCustomerList().stream().findFirst();
            if (optCustomer.isPresent()) {
                Customer customer = optCustomer.get();
                legacyAccountNumber = customer.getAccno();
            }
        } else {

            Optional<AccountTypeMap> optAccountTypeMap = accountTypeMapRepository.findByAccountTypeCodeAndAccountSubTypeCode(galaxyData.getAccount().getAccountTypeCode(), galaxyData.getAccount().getAccountSubTypeCode());
            if (optAccountTypeMap.isPresent()) {
                AccountTypeMap accountTypeMap = optAccountTypeMap.get();
                String accountGroup = accountTypeMap.getAccountGroup();
                String branchCode = galaxyData.getAccount().getAccountTypeCode();
                String cbiDb = accountTypeMap.getCbiDb();
                String cbiCr = accountTypeMap.getCbiCr();
                String cbkDb = accountTypeMap.getCbkDb();
                String cbkCr = accountTypeMap.getCbkCr();
                GenerateAccountNumberResponse response = rangeService.generateAccountNumber(branchCode, accountGroup, cbiDb, cbiCr, "  25E", "  60A");
                legacyAccountNumber = response.getResponse().getAccountNo().toString();
                threadLocalUtil.addKey(trackingCodeKey, response.getResponse().getTrackingCode());
                threadLocalUtil.addKey(isNewRecordKey, true);
            }

        }
        log.warn("#########  legacyAccountNumber {}", legacyAccountNumber);

        return legacyAccountNumber;
    }
}

当我调试或运行应用程序时,Customer可以更新,但当我想更新CustomerPerson时,它会在PK上抛出ConstraintViolationException以更新实体。有什么建议吗?我原以为它有equals和hashcode的功能,但我写的equals和hashcode客户相同。

外部服务是SyncLegacyAccountServiceImpl

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class SyncLegacyAccountServiceImpl implements ISyncLegacyAccountService {

    private static final Logger log = LoggerFactory.getLogger(GalaxyService.class);

    @Value("${range.trackingCodeThreadLocalKey}")
    private String trackingCodeKey;
    @Value("${customer.sync.isNewRecord}")
    private String isNewRecordKey;

    private final IMQService iMQService;
    private final IAccountRequestService iAccountRequestService;
    private final CustomerService customerService;
    private final GalaxyService galaxyService;
    private final RangeService rangeService;
    private final ThreadLocalUtil threadLocalUtil;

    @Override
    @Transactional
    public void handleSyncRequest(Event event) {
        try {
            rangeCompensation();
            Long newAccountNumber = Long.valueOf(event.getArgument().get(Constants.KEY_ACCOUNT_NO_MQ).toString());
            CustomerAccountResponseDto galaxyData = galaxyService.getGalaxyData(String.valueOf(newAccountNumber));
            String legacyAccountNumber = customerService.syncAccount(newAccountNumber, galaxyData);
            log.info("legacy no {}",legacyAccountNumber);
            iMQService.send(MQUtil.buildAccountChangeResponse(null, legacyAccountNumber, event.getMessageId()));
            iAccountRequestService.saveSuccessfulAccountRequest(event);
            log.info("saved succed");
            updateRangeToFinal();
            log.info("updateRangeToFinal");
        } catch (Exception exception) {
            log.error(exception.toString());
            updateRangeToRevoke();
        }
    }

    private void updateRangeToFinal() {
        Boolean isNewRecord = (Boolean) threadLocalUtil.getKey(isNewRecordKey);
        if (!ObjectUtils.isEmpty(isNewRecord)) {
            if (isNewRecord) {
                rangeService.updateToFinal(String.valueOf(threadLocalUtil.getKey(trackingCodeKey)));
                removeFromThreadLocal(trackingCodeKey);
                removeFromThreadLocal(isNewRecordKey);
            }
        }
    }

    private void updateRangeToRevoke() {
        Boolean isNewRecord = (Boolean) threadLocalUtil.getKey(isNewRecordKey);
        if (!ObjectUtils.isEmpty(isNewRecord)) {
            if (isNewRecord) {
                rangeService.updateToRevoke(String.valueOf(threadLocalUtil.getKey(trackingCodeKey)));
                removeFromThreadLocal(trackingCodeKey);
                removeFromThreadLocal(isNewRecordKey);
            }
        }
    }

    private void rangeCompensation() {
        if (!ObjectUtils.isEmpty(threadLocalUtil.getKey(trackingCodeKey)) && !ObjectUtils.isEmpty(threadLocalUtil.getKey(isNewRecordKey))) {
            updateRangeToRevoke();
        }
    }

    private void removeFromThreadLocal(String key) {
        threadLocalUtil.removeKey(key);
    }

日志

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [SGB.C_PR_PK]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only

我知道这个场景中的违规例外是什么。但这很奇怪,因为,Customer实体以同样的方式正确更新。但是当它想要更新CustomerPerson时,它抛出这个异常。我用equals方法检查,以确保更新的对象与Db-one(ID)相同--

共有2个答案

李嘉胜
2023-03-14

这里只是一个猜测,但可能发生的情况如下:

CustomerPerson cpSaved = customerPersonRepository.findCustomerPersonByNewlabChrono(customerPerson.getNewlabChrono()); 

检索ID=XX的特定CustomPerson

BeanUtils.copyProperties(customerPerson, cpSaved); 

cpSaved(ID)正在被此方法替换为可能ID=YY

///错误发生在这里,(ID)现在是YY,但它已经存在,它实际上是试图创建一个新的OBJECT,而不是更新实体。

夹谷俊远
2023-03-14

DataIntegrityViolationException表示代码试图以数据库方案禁止的方式修改数据库。缩写“PK”通常意味着“主键”,因此您的代码可能试图插入一个具有重复ID的行。

 类似资料:
  • 这是列表类 下面是执行类 以下是控制器删除列表的方法 当我执行上述代码时,我得到以下错误 详细信息:键(id)=(1)仍然从表“执行”中引用。 在删除具有特定id的列表表之前,如何删除具有列表id的执行表? 任何帮助都将不胜感激。非常感谢。

  • 我有一个MathematicsAnswer引用的实体数学。如果对数学执行post请求,我会得到一个例外,即MathsAnswer上的字段不能为空。但我确实在球场上跳了起来。拜托,我需要这个解决方案<代码>java.sql。SQLIntegrityConstraintViolationException:列'question_id'不能为空。 sql架构: 实体类: MathsAnswers.jav

  • 问题内容: 我试图在我的注释表中插入值,但出现错误。俗话说,我不能添加或更新子行,我也不知道这意味着什么。 我的架构看起来像这样 和我试图做的mysql语句看起来像这样 我得到的错误看起来像这样 SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败(。,CONSTRAINT FOREIGN KEY()引用()删除无操作,更新无操作) 问题答案: 这只是意味着您

  • 我正在通过这个类更新一些值,createdBy和lastModifiedBy的值不是必须更新的。所以,我不是从邮递员那里传递这些值。它接受lastModifiedBy列,但当我不传递createdBy值时,它会显示sql异常。为什么会这样? 控制台如下所示: 在org。springframework。aop。框架反射方法调用。继续(ReflectiveMethodInvocation.java:1

  • 我正在使用Spring和Hibernate,我得到了这个例外。以下是我试图获得的:我有User和UserSettings类,它们以OneToMany和ManyToOne注释为界,如下所示: 现在,我想为用户添加设置,我是这样做的: 问题来了:UserSettings中的用户持有旧设置和新设置的集合(设置,我刚刚创建并想要添加),但旧设置持有用户的集合,其中没有新设置。我想这就是为什么我会遇到异常,

  • 在这种情况下,我希望检索数据,但在返回数据之前,我希望在不保存/持久化的情况下对其进行更改。 这是我的Rest控制器: 以下是服务实现: 最初我在服务上有注释。通过删除它而不在方法中使用它,我首先想到的是会话将使用存储库打开和关闭,如这里的答案所示。 这不起作用,我在评论中看到“会话将持续整个HTTP请求处理过程。”所以,在我添加的服务中 然后在我添加的方法中 在我做任何改变之前。然而,我所做的任