cuando tenemos 2 entidades por ejemplo
Pedidos -> this one is the Parent @OneToMany
PedidosDetalle -> this one is the Child @ManyToOne
@OneToMany(cascade=CascadeType.ALL,mappedBy="pedidos",fetch = FetchType.EAGER)
private List<PedidosDetalle> pedidosdetalle;
y queremos eliminar algun registro dentro de PedidosDetalle, lo podemos hacer de la siguiente forma, en mi caso cuando removi un registro de PedidosDetalle y luego realize merge o persist a Pedidos no me actualizaba el cambio que realizaba, de esta manera efectivamente lo pude lograr asi:
public void deletePedidosDetalles(int id) {
Query query = em.createQuery("delete From PedidosDetalle where id=:id");
query.setParameter("id", id);
int resultado = query.executeUpdate();
if(resultado>0){
System.out.println("Registro eliminado...........[OK]");
}
}
No comments:
Post a Comment