Home » Eclipse Projects » EclipseLink » eclipselink does two inserts and one update when using cyclic references
eclipselink does two inserts and one update when using cyclic references [message #669831] |
Wed, 11 May 2011 18:04 |
Luiz E. Messages: 100 Registered: September 2010 |
Senior Member |
|
|
hi all
i'm using cyclic references in a model like this:
@Entity
public class LancamentoNF extends BaseEntityObject implements Serializable {
@ManyToOne(cascade={CascadeType.PERSIST})
//@JoinColumn(name="lancamentos")
private MovFiscalContabil lancamentos = new MovFiscalContabil();
@Entity
@Table(name ="movfiscalcontabil")
public class MovFiscalContabil extends BaseEntityObject implements Serializable {
@ManyToOne
//@JoinColumn(name="id")
private LancamentoNF lancamentoNF;
but when i save the entity (LancamentoNF) the following occurs:
[EL Fine]: 2011-05-11 14:57:06.484--Connection(25881278)--INSERT INTO movfiscalcontabil (TIPOIMPOSTO, VALORICMS, VALORIPI, VALORDEBITO, VALORCREDITO, lancamentoscontabeis_id, empresas_id, planoContaDebito, LANCAMENTONF_ID, movimentoduplicatas_id, itensnf_id, planoContaIcms, planoContaIpi, planoContaCredito) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2011-05-11 14:57:06.484--Connection(25881278)-- bind => [null, 10.0, 10.0, 1010.0, 990.0, null, null, null, null, null, null, null, null, null]
[EL Fine]: 2011-05-11 14:57:06.484--Connection(25881278)--select lastval()
[EL Fine]: 2011-05-11 14:57:06.484--Connection(25881278)--INSERT INTO LANCAMENTONF (CLIENTEFORNECEDORCOMPLEMENTO, BASECALCULO, CLIENTEFORNECEDORCEP, VALORIPI, CLIENTEFORNECEDORNUMERO, VALORTOTALNOTA, CLIENTEFORNECEDORINSCRICAOESTADUAL, CLIENTEFORNECEDORINSCRICAOMUNICIPAL, CLIENTEFORNECEDORLETRA, TIPODOCUMENTO, CLIENTEFORNECEDORMUNICIPIO, CLIENTEFORNECEDORNM, VALORPARCIALNOTA, CLIENTEFORNECEDORTIPOLOGRADOURO, CLIENTEFORNECEDORENDERECO, VALORICMS, NUMERO, SERIE, CLIENTEFORNECEDORFANTASIA, DATALANCAMENTO, DATAEMISSAO, CLIENTEFORNECEDORENDERECOCOMPLETO, CLIENTEFORNECEDORCPFCNPJ, ESPECIE, CLIENTEFORNECEDORUF, cfop_id, parametrosCFOP, tipologradouro_id, clientefornecedor_id, LANCAMENTOS_MOVFISCALCONTABIL_ID, modelonf_id, empresas_id, condicaopagamento_id, municipios_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2011-05-11 14:57:06.484--Connection(25881278)-- bind => [Casa de esquina, 0.0, 85904130, 10.0, 1, 1010.0, , , a, 1, Exterior, Diogo Bla, 1000.0, Avenida, dasdsada, 10.0, 344, AB, Diogo, 2011-05-11, 2011-05-11, Avenida dasdsada, 1 - Centro - Exterior/Exterior, 051.092.549-90, NF, PR, 252, null, null, 3, 4, 40, 1, 1, null]
[EL Fine]: 2011-05-11 14:57:06.5--Connection(25881278)--select lastval()
[EL Fine]: 2011-05-11 14:57:06.5--Connection(25881278)--UPDATE movfiscalcontabil SET planoContaIcms = ?, VALORICMS = ?, VALORCREDITO = ?, VALORDEBITO = ?, planoContaCredito = ?, planoContaIpi = ?, LANCAMENTONF_ID = ?, VALORIPI = ?, empresas_id = ?, planoContaDebito = ? WHERE (MOVFISCALCONTABIL_ID = ?)
[EL Fine]: 2011-05-11 14:57:06.5--Connection(25881278)-- bind => [376, 10.0, 990.0, 1010.0, 120, 377, 6, 10.0, 1, 4, 4]
as the log says, he does a insert, then another insert, and then a update. but the problem is that for me, that update doesn't make any sense! I've debugged the app before saves the LancamentoNF entity, and the MovFiscalContabil is pretty fine!
i tried with and without the @joincolumn but had no success.
any ideas?
thanks a lot
[Updated on: Wed, 11 May 2011 18:11] Report message to a moderator
|
|
| |
Re: eclipselink does two inserts and one update when using cyclic references [message #670054 is a reply to message #669831] |
Thu, 12 May 2011 14:07 |
|
The log looks correct. Because you have a foreign key relationship in both directions you have made it impossible to insert into the tables, to resolve this EclipseLink does a "shallow" insert, then an update of the foreign keys to ensure the foreign key constraints are not violated.
This seems to be working correctly, what is your issue?
In general you model seems wrong, it seems the two objects have a OneToOne relationship not a ManyToOne, you should use a OneToOne and have only one foreign key and use mappedBy in the other.
James : Wiki : Book : Blog : Twitter
|
|
| | |
Goto Forum:
Current Time: Thu Sep 19 15:39:02 GMT 2024
Powered by FUDForum. Page generated in 0.04199 seconds
|