好
我是HIbernate的新手,正在遇到一个问题,我需要支持才能尝试解决它。
我有一个Client类,该类包含组合键。
@Entity
@Table(name = "Clientes")
@IdClass(ClientePK.class)
public class Cliente implements Serializable {
//@EmbeddedId
//private ClientePK clientePK;
@Id
@Column(name = "Id_Cliente", nullable = false, length = 15)
private long idCliente;
@Id
@Fetch(FetchMode.SELECT)
@ManyToOne
@JoinColumn(name = "Loja", nullable = false)
private Loja loja;
}
public class ClientePK implements Serializable {
private long idCliente;
private Loja loja;
}
然后我有一个ClientClass类,其中也包含复合键
@Entity
@Table(name = “Clientes_Historicos”)
@IdClass(ClienteHistoricoPK.class)
public class ClienteHistorico implements Serializable {
@Id
@Resolvable(colName = "Id. Cliente Histórico")
@Column(name = "Id_Cliente_Historico", nullable = false)
private Long idClienteHistorico;
@Id
@Fetch(FetchMode.SELECT)
@ManyToOne
@JoinColumn(name = "Loja", nullable = false)
private Loja loja;
@Resolvable(colName = "Cliente")
@Fetch(FetchMode.SELECT)
@JoinColumns({
@JoinColumn(name = "id_cliente", referencedColumnName = "Id_Cliente", nullable = false, insertable = true)
,
@JoinColumn(name = "loja", referencedColumnName = "loja", nullable = false, insertable = false, updatable = false)
})
@MapsId("loja")
@ManyToOne(optional = false)
private Cliente cliente;
}
我使用@MapsId注释(“ store”)表示主键的store字段应与客户端连接本身的FK字段一起使用。
发生这种情况是,在ClientHistorico中执行插入操作时,没有考虑将客户字段插入。
Informações: Hibernate: insert into Clientes_Historicos (Data, Tipo, Usuario, Id_Cliente_Historico, Loja) values (?, ?, ?, ?, ?)
WARN: SQL Error: 1400, SQLState: 23000
ERROR: ORA-01400: não é possível inserir NULL em ("MARTINELLO"."CLIENTES_HISTORICOS"."ID_CLIENTE")
Informações: HHH000010: On release of batch it still contained JDBC statements
ERROR: HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
谢谢。