0

我有 3 个相关类:ParametrosEntity、NomFicherosEntity 和 TipoCamposEntity。当试图持久化一个 ParametrosEntity 对象时,问题就来了,为它提供了另外两个所需的对象。

参数实体:

@Entity
@Table(name = "CON_DPARAMETROS")
public class ParametrosEntity {

@EmbeddedId
@AttributeOverrides({
        @AttributeOverride(name = "componenteId", column = @Column(name = "COM_IDENTIFICADOR",
                                                                   nullable = false)),
        @AttributeOverride(name = "clave", column = @Column(name = "PAR_CLAVE",
                                                            nullable = false)),
        @AttributeOverride(name = "fichero", column = @Column(name = "NOM_FICHERO",
                                                              nullable = false))})
private ParametrosPK id;
@Column(name = "PAR_VALOR")
private String valor;
@Column(name = "PAR_LABEL")
private String label;
@Column(name = "PAR_DESCRIPCION")
private String descripcion;
@Column(name = "PAR_PRESENTACION")
private String presentacion;
@Column(name = "PAR_PROGRAMA")
private String programa;

@OneToOne
@JoinColumns({
        @JoinColumn(name = "COM_IDENTIFICADOR", referencedColumnName = "COM_IDENTIFICADOR",
                    nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "NOM_FICHERO", referencedColumnName = "NOM_FICHERO",
                    nullable = false, insertable = false, updatable = false)})
private NombreFicherosEntity fichero;
@OneToOne
@JoinColumn(name = "TIP_TIPO", nullable = false, insertable = false, updatable = false)
private TipoCamposEntity tipo;

TipoCamposEntity:

@Entity
@Table(name = "CON_PTIPOCAMPOS")
public class TipoCamposEntity {

@Id
@Column(name = "TIP_TIPO")
private String tipo;
@Column(name = "TIP_DESCRIPCION")
private String descripcion;

NomFicheros 实体:

@Entity
@Table(name = "CON_DNOMFICHEROS")
public class NombreFicherosEntity {

@EmbeddedId
@AttributeOverrides({
        @AttributeOverride(name = "idComponente", column = @Column(name = "COM_IDENTIFICADOR",
                                                                   nullable = false)),
        @AttributeOverride(name = "fichero", column = @Column(name = "NOM_FICHERO",
                                                              nullable = false))})
private NombreFicherosPK id;

@OneToOne
@JoinColumn(name = "COM_IDENTIFICADOR", nullable = false, insertable = false, updatable = false)
private ComponentesEntity componente;

我在尝试持久化 ParametrosEntity 对象时遇到问题。我将数据分配给对象 ParametrosEntity,包括所需的实体,但插入时出现错误。

这是我用于持久化的代码和获得的错误:

持久化代码:

参数实体参数 = 新参数实体();

    Session session = HibernateUtil.getSession();
    Transaction tx = null;
    tx = session.beginTransaction();

    ParametrosPK paramPK = new ParametrosPK();

    paramPK.setClave("clave");
    paramPK.setComponenteId("SGACAC");
    paramPK.setFichero("sgacac");

    param.setId(paramPK);

    param.setDescripcion("dfasfasfadfaf");
    param.setLabel("label");

    param.setFichero(buscarNomPorIdyNombre("SGACAC", "sgacac")); //  This obtain an existing NombreFicherosEntity from the DB
    param.setTipo(buscarTipoPorTipo("Texto")); // This obtains an existing TipoCamposEntity from the DB

    session.save(param);

    tx.commit();

    session.close();

并且有错误的输出:

Hibernate: insert into CON_DPARAMETROS (PAR_DESCRIPCION, PAR_LABEL, PAR_PRESENTACION, PAR_PROGRAMA, PAR_VALOR, PAR_CLAVE, COM_IDENTIFICADOR, NOM_FICHERO) values (?, ?, ?, ?, ?, ?, ?, ?)
ORA-01400: cannot insert NULL into ("SGAINSDIST"."CON_DPARAMETROS"."TIP_TIPO")

我可以看到休眠在插入查询中不包括“TIP_TIPO”列,但我不明白为什么不。¿我在这里做错了什么?谢谢您的帮助。

4

0 回答 0