Java 持久化对象的可插入、可更新属性行为
我有一个实体如下Java 持久化对象的可插入、可更新属性行为,java,jpa,openjpa,Java,Jpa,Openjpa,我有一个实体如下 @Entity @Table(name="DATMLAUENDCTT") public class EnderecoContatoLaudoEntity implements Serializable { /** A Constante serialVersionUID. */ private static final long serialVersionUID = 1L; /** O id. */ @EmbeddedId priva
@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为null。
但是我正在设置对象tipotelefonentity
,它对应于列TELTIPSEQNUM
现在,当我删除insertable=false、updateable=false时,如下所示:
/**O电话号码*/
@列(name=“TELTIPSEQNUM”)
私人长数字序列电话
然后,坚持工作
插入是否应该使用对象的TELTIPSEQNUM
,该对象位于嵌入id对象之外?
简单,如果使用
insertable = false
JPA客户端不会在新对象中插入该值,这应该是如何工作的
从文件:
public abstract boolean insertable
(Optional) Whether the column is included in SQL INSERT statements generated by the persistence provider
但是在实体EndereContatoLaundoEntity中,TipoTelefoneEntity属性中没有可更新和可插入的,因此它应该将列添加到语句中,对吗?这就是我要问的@ManyToOne@JoinColumn(name=“TELTIPSEQNUM”,referencedColumnName=“TELTIPSEQNUM”)私有tipotelefonentity tipotelefonentity;