API调用上的org.springframework.dao.DataIntegrityViolationException

时间:2018-11-05 12:07:38

标签: java spring spring-mvc spring-boot spring-data

试图理解一段未能向数据库添加新行的代码。进行API调用的是一家公司的注册:

@PostMapping("/register")
public Company register(@Valid @RequestBody UserRegistrationModel newCompany, BindingResult bindingResult) {
    Category cat = this.catRepo.findByName("Andere");
    if (!bindingResult.hasErrors()) {
        return this.createCompany(newCompany).get();
    } else {
        // throw fancy error!
        throw new InvalidRequestException("There were binding errors!", null);
    }
}

POST失败,并显示以下语句:

{timestamp: 1541400035590, status: 500, error: "Internal Server Error",…}

error: "Internal Server Error"

exception: "org.springframework.dao.DataIntegrityViolationException"

message: "could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"

path: "/api/companies/register"

status: 500

timestamp: 1541400035590

我应该先去哪里看?数据库约束?

0 个答案:

没有答案