持久化对象的可插入,可更新属性行为

时间:2014-06-03 20:47:12

标签: java jpa openjpa

我有一个实体如下

@Entity
@Table(name="DATMLAUENDCTT")
public class EnderecoContatoLaudoEntity implements Serializable {

    /** A Constante serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** O id. */
    @EmbeddedId
    private EnderecoContatoLaudoEntityPK id;

    /** O nome contato. */
    @Column(name="CTTNOM")
    private String nomeContato;

    /** O Codigo ddd telefone contato. */
    @Column(name="CTTTELDDDCOD")
    private BigDecimal codigoDDDTelefoneContato;

    /** O numero telefone contato. */
    @Column(name="CTTTELNUM")
    private BigDecimal numeroTelefoneContato;

    //bi-directional many-to-one association to TipoTelefoneEntity
    /** O tipo telefone entity. */
    @ManyToOne
    @JoinColumn(name="TELTIPSEQNUM",referencedColumnName="TELTIPSEQNUM")
    private TipoTelefoneEntity tipoTelefoneEntity;

    //bi-directional many-to-one association to EnderecoLaudoEntity
    /** O endereco laudo entity. */
    @ManyToOne
    @JoinColumns({
        @JoinColumn(name="LAUSEQNUM", referencedColumnName="LAUSEQNUM"),
        @JoinColumn(name="ENDTIPSEQNUM", referencedColumnName="ENDTIPSEQNUM")
    })
    private EnderecoLaudoEntity enderecoLaudoEntity;

它的嵌入式ID如下:

@Embeddable
public class EnderecoContatoLaudoEntityPK implements Serializable {
    //default serial version id, required for serializable classes.
    /** A Constante serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** Coloquei os nomes das colunas que não vieram quando foi gerada pelo RAD. */
    @Column(name = "LAUSEQNUM", insertable = false, updatable = false)
    private long numeroSequenciaLaudo;

    /** O numero sequencia tipo endereco. */
    @Column(name = "ENDTIPSEQNUM", insertable = false, updatable = false)
    private long numeroSequenciaTipoEndereco;

    /** O numero sequencia tipo telefone. */
    @Column(name = "TELTIPSEQNUM", insertable = false, updatable = false)
    private long numeroSequenciaTipoTelefone;

我的问题是,当我尝试保留实体时,为什么插入不起作用?

错误告诉我TELTIPSEQNUM为空。 但我正在设置对应于列tipoTelefoneEntity的对象TELTIPSEQNUM

现在,当我删除insertable = false,updatable = false时,如下所示:

/ ** O numero sequencia tipo telefone。 * /     @Column(name =“TELTIPSEQNUM”)     private long numeroSequenciaTipoTelefone;

然后坚持下去。

插件是否应该使用对象TELTIPSEQNUM中的TipoTelefoneEntity,它位于嵌入式ID对象之外?

1 个答案:

答案 0 :(得分:0)

简单,如果你使用

insertable = false

JPA客户端不会在新对象中插入该值,应该如何工作 来自文档:

public abstract boolean insertable
(Optional) Whether the column is included in SQL INSERT statements generated by the persistence provider