简体   繁体   English

ORA-01400 无法在一对一关系中插入 null 错误

[英]ORA-01400 cannot insert null error in one to one relationship

i have this code我有这个代码

public void guardarAspirante(AspiranteDTO aspiranteDTO) {
    Aspirante aspirante = new Aspirante();
    String usuarioMovimiento = AspiranteCN.class.getSimpleName();
    Date fecha = new Date();
    aspirante.setCodigoAlumno(aspiranteDTO.getCodigoUniversitario());
    aspirante.setNombre(aspiranteDTO.getNombre());
    aspirante.setApellidoPaterno(aspiranteDTO.getPrimerApellido());
    aspirante.setApellidoMaterno(aspiranteDTO.getSegundoApellido());
    aspirante.setUsuarioMovimiento(usuarioMovimiento);
    aspirante.setFechaMovimiento(fecha);

    Solicitud solicitud = new Solicitud(aspirante.getSolicitudId());
    solicitud.setAspirante(aspirante);
    solicitud.setSolicitudId(aspirante.getSolicitudId());
    solicitud.setOfertaId(aspiranteDTO.getOfertaAcademica());
    solicitud.setPeriodoId(aspiranteDTO.getPeriodo());
    solicitud.setAportacion(aspiranteDTO.getAportacionVoluntaria());
    solicitud.setFechaMovimiento(fecha);
    solicitud.setUsuarioMovimiento(usuarioMovimiento);
    aspirante.setSolicitud(solicitud);

    ....

    aspiranteDAO.persist(aspirante);

} }

and this error这个错误

Internal Exception: java.sql.SQLException: ORA-01400: cannot insert NULL into ("RPINGRE"."ARE_SOLI"."ARE_SOLI_SOLIASPI_ID")内部异常:java.sql.SQLException:ORA-01400:无法将 NULL 插入(“RPINGRE”.“AREIASPISOLID”)

This is Aspirante Entity (Fragment)这是Aspirante Entity(片段)

@Entity
@Table(name = "ARE_SOLIASPI", catalog = "", schema = "RPINGRE")
public class Aspirante implements Serializable {
private static final long serialVersionUID = 1L;
@SequenceGenerator(sequenceName = "RPINGRE.SQ_ARE_SOLIASPI",
name = "RPINGRE.SQ_ARE_SOLIASPI",
initialValue = 1,
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RPINGRE.SQ_ARE_SOLIASPI")
@Id
@Basic(optional = false)
@Column(name = "ARE_SOLIASPI_ID")
private Long solicitudId;
@Basic(optional = false)
@Column(name = "ARE_SOLIASPI_CODIGO")
private String codigoAlumno;
@Basic(optional = false)
@Column(name = "ARE_SOLIASPI_NOMBRE")
private String nombre;
@Column(name = "ARE_SOLIASPI_APE_PATERNO")
private String apellidoPaterno;
@Column(name = "ARE_SOLIASPI_APE_MATERNO")
private String apellidoMaterno;
@Basic(optional = false)
@Column(name = "ARE_SOLIASPI_MOV_USUARIO")
private String usuarioMovimiento;
@Basic(optional = false)
@Column(name = "ARE_SOLIASPI_MOV_FECHA")
@Temporal(TemporalType.TIMESTAMP)
private Date fechaMovimiento;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "aspirante", fetch = FetchType.LAZY)
private Solicitud solicitud;

and Solicitud Entity (Fragment)Solicitud实体(片段)

@Entity
@Table(name = "ARE_SOLI", catalog = "", schema = "RPINGRE")
public class Solicitud implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "ARE_SOLI_SOLIASPI_ID")
private Long solicitudId;
@Basic(optional = false)
@Column(name = "ARE_SOLI_MOV_USUARIO")
private String usuarioMovimiento;
@Basic(optional = false)
@Column(name = "ARE_SOLI_MOV_FECHA")
@Temporal(TemporalType.TIMESTAMP)
private Date fechaMovimiento;
@Column(name = "ARE_SOLI_PERIODO_ID")
private String periodoId;
@Column(name = "ARE_SOLI_OFERTA_ID")
private Long ofertaId;
@Column(name = "ARE_SOLI_APORTACION")
private Long aportacion;
@JoinColumn(name = "ARE_SOLI_SOLIASPI_ID", referencedColumnName = "ARE_SOLIASPI_ID", insertable = false, updatable = false, nullable = false)
@OneToOne(optional = false, fetch = FetchType.LAZY)
private Aspirante aspirante;

.....
}

try changing GenerationType.SEQUENCE to GenerationType.Auto .尝试将GenerationType.SEQUENCE更改为GenerationType.Auto

The ORA-01400 error says that you are trying to insert a NULL into a column defined as NOT NULL. ORA-01400 错误表示您正在尝试将 NULL 插入定义为 NOT NULL 的列中。 I suggest you ether set a default value on the column or have your code make sure the NOT NULL columns have data before you do the INSERT (or use an NVL function in your INSERT statement)我建议您在列上设置默认值或让您的代码确保 NOT NULL 列在您执行 INSERT 之前有数据(或在您的 INSERT 语句中使用 NVL function)

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

相关问题 oracle.jdbc.OracleDatabaseException: ORA-01400: 不能插入 NULL - oracle.jdbc.OracleDatabaseException: ORA-01400: cannot insert NULL into oracle.jdbc.OracleDatabaseException: ORA-01400: cannot insert NULL into ("SCOTT"."D_TEST"."DTESTID") in spring boot jpa - oracle.jdbc.OracleDatabaseException: ORA-01400: cannot insert NULL into ("SCOTT"."D_TEST"."DTESTID") in spring boot jpa ORA-01400:使用Hibernate插入外键时出错 - ORA-01400: Error while inserting Foreign Key using Hibernate 无法在一对多关系hibernate注释中插入null - cannot insert null in one to many relationship hibernate annotation Hibernate:插入多对一:错误列不能为空 - HIbernate: insert many to one: error Column cannot be null 将空值保存到多对一休眠关系错误 - Save null value to many-to-one hibernate relationship error 保存一对一关系:空指针异常 - Saving One to One Relationship: Null pointer Exception Spring Data Jpa一对多的关系。 无法插入子记录:外键为NULL - Spring Data Jpa one to many relationship. Not able to insert child records: foreign key is coming as NULL 休眠-以一对多关系插入数据 - Hibernate - insert data with one to many relationship Hibernate一对多关系java.sql.SQLIntegrityConstraintViolationException:列'person_id'不能为null - Hibernate one-to-many relationship java.sql.SQLIntegrityConstraintViolationException: Column 'person_id' cannot be null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM