【发布时间】:2021-05-26 13:07:24
【问题描述】:
我在添加到候选人表时遇到此错误。候选人表扩展了用户表。邮箱和密码列来自这个表。我觉得是数据库有问题,我用的是postreSql。会是什么原因?
用户表
package com.example.hrmsdemo.entities.concretes;
import com.sun.istack.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name="users",uniqueConstraints = {@UniqueConstraint(columnNames = {"email"})})
@Inheritance(strategy = InheritanceType.JOINED)
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull
private int id;
@Column(name = "email")
@NotNull
private String email;
@NotNull
@Column(name = "password")
private String password;
}
候选人表
package com.example.hrmsdemo.entities.concretes;
import com.sun.istack.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name="candidates",uniqueConstraints = {@UniqueConstraint(columnNames = {"identity_number"})})
@EqualsAndHashCode(callSuper = true)
@Entity
public class Candidate extends User {
@Column(name = "first_name")
@NotNull
private String first_name;
@NotNull
@Column(name = "last_name")
private String last_name;
@NotNull
@Column(name = "identity_number")
private String identity_number;
@NotNull
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Column(name = "birth_date")
private Date birth_date;
}
错误
2021-05-26 15:59:53.230 WARN 24964 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23502
2021-05-26 15:59:53.230 ERROR 24964 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : HATA: null value in column "email_address" of relation "users" violates not-null constraint
Ayrıntı: Hata veren satır (7, null, 123414, veyselhim@gmail.com) içeriyor.
2021-05-26 15:59:53.245 ERROR 24964 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [email_address" of relation "users]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
【问题讨论】:
-
为什么要在 PosgreSQL 问题中添加 Microsoft SQL Server 标记?我删除了不适当的标签并添加了正确的标签,以提高您获得答案的机会。
-
谢谢先生,我没看到
标签: java spring postgresql hibernate