简体   繁体   English

null 关系“技术”的“id”列中的值违反了非空约束 (PostgreSQL)

[英]null value in column "id" of relation "technologies" violates not-null constraint (PostgreSQL)

Technology and technologyManager classes as shown below: Im trying to add a technology to database by swagger-ui but get an exception of null value in column "id" of relation "technologies" violates not-null constraint Technology 和 technologyManager 类如下所示:我试图通过 swagger-ui 将技术添加到数据库,但在关系“technologies”的“id”列中出现 null 值的异常违反了非空约束

public class Technology {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private int id;

@Column(name="name")
private String name;

@ManyToOne(cascade = CascadeType.DETACH)
@JoinColumn(name = "language_id")
private ProgrammingLanguage language;
}
public void add(CreateTechnologyRequest technologyRequest) throws Exception {
    Technology technology = new Technology();
    
    
    if(technologyRequest.getName().isBlank()) {
        throw new Exception("Please enter a name");
    }else{
        for(Technology technologies : technologyRepository.findAll()) {
            if(technologies.getName().equalsIgnoreCase(technologyRequest.getName())) {
                throw new Exception("This name is already exist.");
            }else {
                
            }       technology.setName(technologyRequest.getName());    
                    
            for(ProgrammingLanguage language : languageRepository.findAll()) {
                
                if(language.getName().equalsIgnoreCase(technologyRequest.getLanguageName())) {
                    technology.setLanguage(language);
                }
            }           
        }
            technologyRepository.save(technology);
    }
    
}

I tried to add a new Technology to database by using swagger-ui but it threw an exception of null value in column "id" even though it is primary key and auto-generated.我尝试使用 swagger-ui 向数据库添加一项新技术,但它在“id”列中抛出了 null 值的异常,即使它是主键并且是自动生成的。

Try with GenerationType.AUTO instead of GenerationType.IDENTITY and change the type of the id from int to Integer or Long尝试使用GenerationType.AUTO而不是GenerationType.IDENTITY并将 id 的类型从int更改为IntegerLong

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关系“invoice”的“header_id”列中的 JPA null 值违反 PostgresSQL 的非空约束 - JPA null value in column "header_id" of relation "invoice" violates not-null constraint with PostgresSQL 错误:关系 xxx 的“id”列中的 null 值违反非空约束 - Spring 数据 JPA - ERROR: null value in column "id" of relation xxx violates not-null constraint - Spring Data JPA 如何修复列“id”中的'null值违反了非空约束'' - How to fix ''null value in column “id” violates not-null constraint'' 突发错误:org.postgresql.util.PSQLException:错误:列“id”中的空值违反非空约束 - Sudden error: org.postgresql.util.PSQLException: ERROR: null value in column “id” violates not-null constraint org.postgresql.util.PSQLException:错误:“ category_id”列中的空值违反了非空约束 - org.postgresql.util.PSQLException: ERROR: null value in column “category_id” violates not-null constraint org.postgresql.util.PSQLException:错误:列“id”中的空值违反非空约束 - org.postgresql.util.PSQLException: ERROR: null value in column “id” violates not-null constraint Postgresql 抛出 null 列“id”中的值违反了 GenerationType.IDENTITY 的非空约束 - Postgresql throws null value in column "id" violates not-null constraint for GenerationType.IDENTITY 由以下原因引起:org.postgresql.util.PSQLException:错误:列“ student_id”中的空值违反了非空约束 - Caused by: org.postgresql.util.PSQLException: ERROR: null value in column “student_id” violates not-null constraint PSQLException:错误:关系“床”的“idRoom”列中的 null 值违反非空约束 - PSQLException: ERROR: null value in column "idRoom" of relation "Bed" violates not-null constraint 带有postgresql的串行列上的Spring Data JPA“xxx列中的空值违反非空约束” - Spring Data JPA "null value in column xxx violates not-null constraint" on serial column with postgresql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM