Java 无法执行语句;SQL[n/a];约束[关系用户的电子邮件地址];嵌套异常
添加到候选表时出现此错误。候选表扩展用户表。电子邮件和密码列来自此表。我认为数据库有问题,我正在使用postreSql。原因是什么 用户表Java 无法执行语句;SQL[n/a];约束[关系用户的电子邮件地址];嵌套异常,java,spring,postgresql,hibernate,Java,Spring,Postgresql,Hibernate,添加到候选表时出现此错误。候选表扩展用户表。电子邮件和密码列来自此表。我认为数据库有问题,我正在使用postreSql。原因是什么 用户表 package com.example.hrmsdemo.entities.concretes; import com.sun.istack.NotNull; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java
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;
}
错误
我假设您真的将
用户#电子邮件
映射到名为电子邮件地址
?这是数据库正在抱怨的列,但您没有显示到该列的映射
假设这是真的,您已经定义了这个属性应该是非空的,这似乎也是数据库的定义方式。这表明您正在尝试保存用户,但未设置其电子邮件属性
或者,您确实没有映射该列,因此Hibernate从未尝试写入该列。从您给我们的内容很难判断。为什么要在PosgreSQL问题中添加Microsoft SQL Server标记?我删除了不合适的标签并添加了正确的标签,以提高您获得答案的机会。谢谢,先生,我在数据库中没有看到这个名字,我在代码中写的名字也不一样,谢谢
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