[英]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.