【问题标题】:insertable, updatable attributes behavior persisting the object持久化对象的可插入、可更新属性行为
【发布时间】:2014-07-24 08:20:36
【问题描述】:

我有一个实体如下

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

然后持久化工作。

插入不应该使用对象TipoTelefoneEntity中的TELTIPSEQNUM,即在嵌入的id对象之外吗?

【问题讨论】:

    标签: java jpa openjpa


    【解决方案1】:

    简单,如果你使用

    insertable = false
    

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

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

    【讨论】:

    • 但是在实体 EnderecoContatoLaudoEntity 中,TipoTelefoneEntity 属性中没有可更新和可插入的,所以它应该将列添加到语句中,对吗?这就是我要问的。 @ManyToOne @JoinColumn(name="TELTIPSEQNUM",referencedColumnName="TELTIPSEQNUM") private TipoTelefoneEntity tipoTelefoneEntity;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多