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

发布于 2024-11-25 02:06:46 字数 3488 浏览 5 评论 0原文

我有这个代码

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);

}

和这个错误

内部异常:java.sql.SQLException:ORA-01400:无法将 NULL 插入(“RPINGRE”。“ARE_SOLI”。“ARE_SOLI_SOLIASPI_ID”)

这是 Aspirante 实体(片段)

@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;

Solicitud< /code> 实体(片段)

@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;

.....
}

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")

This is Aspirante Entity (Fragment)

@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)

@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;

.....
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你爱我像她 2024-12-02 02:06:46

尝试将 GenerationType.SEQUENCE 更改为 GenerationType.Auto

try changing GenerationType.SEQUENCE to GenerationType.Auto.

绻影浮沉 2024-12-02 02:06:46

ORA-01400 错误表明您试图将 NULL 插入到定义为 NOT NULL 的列中。
我建议您在执行 INSERT 之前在列上设置默认值,或者让您的代码确保 NOT NULL 列有数据(或在 INSERT 语句中使用 NVL 函数)

The ORA-01400 error says that you are trying to insert a NULL into a column defined as 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文