【发布时间】: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对象之外吗?
【问题讨论】: