Se eu passar um mapa com varios id’s, dá erro abaixo, se faço apenas 1, da certo e não dá o erro abaixo.
Erro Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.5.v20170607-b3d05bd):
org.eclipse.persistence.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException:
ERROR: could not serialize access due to read/write dependencies among transactions Detalhe:
Reason code: Canceled on identification as a pivot,
during write.
Dica: The transaction might succeed if retried. Error Code: 0 Call:
DELETE FROM financeiro.fatura WHERE (id = ?) bind => [50] Query: DeleteObjectQuery(br.com.dblinked.model.financeiro.Fatura@1f061a44)
///////
@POST
@Compress
@Decompress
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/delete-fatura")
public Response deleteFatura(Map<String, Object> map) {
Map<String, Object> mapResponse = new HashMap<>();
try {
Fatura fatura = persistenceProvider.find(Fatura.class, Integer.parseInt(map.get("idFatura").toString()));
persistenceProvider.removeAndCommit(fatura);
} catch (Exception e) {
mapResponse.put("severity", "error");
mapResponse.put("summary", "Erro");
mapResponse.put("detail", e.getMessage());
}
return JsonUtil.jsonResponseOk(mapResponse);
}
Entitys
////Fatura
@Entity
@Table(name = “fatura”, schema = “financeiro”)
public class Fatura {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@JoinColumn(name = "empresa_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Empresa empresa;
@Size(max = 255)
@Column(name = "numero")
private String numero;
@Size(max = 255)
@Column(name = "nome_favorecido")
private String nomefavorecido;
@Column(name = "data_vencimento")
@Temporal(TemporalType.DATE)
private Date dataVencimento;
@Column(name = "data_fechamento")
@Temporal(TemporalType.DATE)
private Date dataFechamento;
@JoinColumn(name = "plano_conta_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private PlanoContas planoContas;
@JoinColumn(name = "status_fatura_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private StatusFatura statusFatura;
@Column(name = "taxa")
private BigDecimal taxa;
@JsonIgnore
@OneToMany(mappedBy = "fatura", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})
private Collection<FaturaItem> faturaItem = new ArrayList<>();
...getters e setters
////FaturaItem
@Entity
@Table(name = “fatura_item”, schema = “financeiro”)
public class FaturaItem{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@JoinColumn(name = "fatura_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Fatura fatura;
@Column(name = "data_compra")
@Temporal(TemporalType.DATE)
private Date dataCompra;
@JoinColumn(name = "participante_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Participante participante;
@JoinColumn(name = "plano_conta_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private PlanoContas planoContas;
@Column(name = "historico")
private String historico;
@JoinColumn(name = "moeda_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Moeda moeda;
@Column(name = "valor_compra")
private BigDecimal valorCompra;
@Column(name = "qtde_parcelas")
private Integer qtdeParcelas;
@Column(name = "valor_parcela")
private BigDecimal valorParcela;
@Column(name = "taxa")
private BigDecimal taxa;
@JsonIgnore
@OneToOne(cascade = CascadeType.ALL, mappedBy = "faturaItem")
private FaturaItemRateio faturaItemRateio;
...getters e setters
—FaturaItem
@Entity
public class FaturaItemRateio {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@JoinColumn(name = "fatura_item_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private FaturaItem faturaItem;
@JoinColumn(name = "cad_ccus_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private CadCcus cadCcus;
@JoinColumn(name = "cad_proj_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private CadProj cadProj;
@Column(name = "porcentagem")
private Integer porcentagem;
...getters e setters