Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » update when removed?
update when removed? [message #642037] Mon, 29 November 2010 15:44 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I'm not quite understanding why the following fairly simple code is not working:

// find delivery
Delivery lDelivery = (nl.reinders.bm.Delivery)lEntityManager.find(nl.reinders.bm. Delivery.class, 54834);

// remove last deliveryline
List<Deliveryline> lDeliverylines = lDelivery.getDeliverylinesWhereIAmDelivery();
Deliveryline lDeliveryline = lDeliverylines.get(lDeliverylines.size() - 1);
lDeliveryline.setDelivery(null);

// store
lEntityManager.getTransaction().begin();
lDelivery = lEntityManager.merge(lDelivery);
lEntityManager.remove(lEntityManager.merge(lDeliveryline));
lEntityManager.getTransaction().commit();

The "setDelivery(null)" sets the deliverynr to null AND removes the instance from the collection in delivery, plus some event code is executed involving Batchbuyorderline. This is what is logged (look what happens to deliveryline):

[EL Finer]: 2010-11-29 16:32:33.602--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--begin transaction
[EL Finest]: 2010-11-29 16:32:33.602--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Merge clone with references nl.reinders.bm.Delivery@1f703a&Deliverynr=54834
[EL Finest]: 2010-11-29 16:32:36.039--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Merge clone with references nl.reinders.bm.Deliveryline@20cdd9&Deliverylinenr=57253&amount=10000
[EL Finest]: 2010-11-29 16:32:36.039--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--The remove operation has been performed on: nl.reinders.bm.Deliveryline@20cdd9&Deliverylinenr=57253&amount=10000
[EL Finest]: 2010-11-29 16:32:36.039--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--The remove operation has been performed on: nl.reinders.bm.Batchbuyorderline@20d63b&Batchbuyordlinenr=57311
[EL Finer]: 2010-11-29 16:32:37.367--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--begin unit of work commit
[EL Finest]: 2010-11-29 16:32:37.383--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query UpdateObjectQuery(nl.reinders.bm.Delivery@1f703a&Deliverynr=54834)
[EL Finest]: 2010-11-29 16:32:37.383--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query UpdateObjectQuery(nl.reinders.bm.Buyorder@69f15&Buyordernr=10877)
[EL Finest]: 2010-11-29 16:32:37.414--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query ReadObjectQuery(name="iArticle" referenceClass=Article )
[EL Finest]: 2010-11-29 16:32:37.414--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query ReadObjectQuery(name="iBatchtype" referenceClass=Batchtype )
[EL Fine]: 2010-11-29 16:32:37.414--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--UPDATE buyorder SET delivered = ?, dwhmodified = ?, dwhby = ?, lazylock = ? WHERE ((buyordernr = ?) AND (lazylock = ?))
bind => [0, 2010-11-29 16:32:26.431, 1, 6, 10877, 5]
[EL Finest]: 2010-11-29 16:32:37.43--UnitOfWork(33121030)--Thread(Thread[main,5,main ])--Execute query UpdateObjectQuery(nl.reinders.bm.Buyorderline@231191&Buyorderlinenr=61264&Delivered=false)
[EL Fine]: 2010-11-29 16:32:37.43--ClientSession(33315911)--Connection(22286350)-- Thread(Thread[main,5,main])--UPDATE buyorderline SET delivered = ?, dwhmodified = ?, dwhby = ?, lazylock = ? WHERE ((buyorderlinenr = ?) AND (lazylock = ?))
bind => [0, 2010-11-29 16:32:26.368, 1, 3, 61264, 2]
[EL Finest]: 2010-11-29 16:32:37.461--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query UpdateObjectQuery(nl.reinders.bm.Deliveryline@20cdd9&Deliverylinenr=57253&amount=10000)
[EL Fine]: 2010-11-29 16:32:37.476--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--UPDATE deliveryline SET deliverynr = ?, dwhmodified = ?, dwhby = ?, lazylock = ? WHERE ((deliverylinenr = ?) AND (lazylock = ?))
bind => [null, 2010-11-29 16:32:26.571, 1, 2, 57253, 1]
[EL Finest]: 2010-11-29 16:32:37.492--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query DeleteObjectQuery(nl.reinders.bm.Batchbuyorderline@20d63b&Batchbuyordlinenr=57311)
[EL Finest]: 2010-11-29 16:32:37.508--UnitOfWork(33121030)--Thread(Thread[main,5,mai n])--Execute query ReadObjectQuery(name="iBatch" referenceClass=Batch )
[EL Fine]: 2010-11-29 16:32:37.508--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--SELECT batchnr, costprice, lazylock, _amount, articlenr, dwhmodified, creationdate, dwhby, inserted, batchtype FROM batch WHERE (batchnr = ?)
bind => [731213]
[EL Fine]: 2010-11-29 16:32:37.523--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--DELETE FROM batchbuyorderline WHERE ((batchbuyordlinenr = ?) AND (lazylock = ?))
bind => [57311, 1]
[EL Finer]: 2010-11-29 16:32:37.539--ClientSession(33315911)--Connection(22286350)- -Thread(Thread[main,5,main])--commit transaction
2010-11-29 16:32:37,586 INFO nl.knowledgeplaza.util.jdbc.Connection.invoke(Connection.jav a:148) #21275235[C21275235]: commit: java.lang.reflect.InvocationTargetException->java.sql.SQLException: Cannot insert a null into column (deliveryline.deliverynr).
2010-11-29 16:32:37,586 INFO nl.reinders.jdbc.ReindersInformixConnection.invoke(ReindersI nformixConnection.java:70) commit: java.lang.reflect.InvocationTargetException->java.sql.SQLException: Cannot insert a null into column (deliveryline.deliverynr).
[EL Warning]: 2010-11-29 16:32:37.601--ClientSession(33315911)--Thread(Thread[main,5, main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot insert a null into column (deliveryline.deliverynr).
Error Code: -391
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicCommitTransaction(DatabaseAccessor.java:420)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAc cessor.commitTransaction(DatasourceAccessor.java:386)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.commitTransaction(DatabaseAccessor.java:403)
at org.eclipse.persistence.internal.sessions.AbstractSession.ba sicCommitTransaction(AbstractSession.java:503)
at org.eclipse.persistence.sessions.server.ClientSession.basicC ommitTransaction(ClientSession.java:155)
at org.eclipse.persistence.internal.sessions.AbstractSession.co mmitTransaction(AbstractSession.java:685)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitTransaction(UnitOfWorkImpl.java:1565)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitTransaction(RepeatableWriteUnitOfWork.java:560 )
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitTransactionAfterWriteChanges(UnitOfWorkImpl.java:1588)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java: 207)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitAndResume(UnitOfWorkImpl.java:1131)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(EntityTransactionImpl.java:84)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commit(EntityTransactionImpl.java:63)
at nl.reinders.bm.BMTestToplink.main(BMTestToplink.java:809)
Caused by: java.sql.SQLException: Cannot insert a null into column (deliveryline.deliverynr).
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3449)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3762)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2574)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2490)
at com.informix.jdbc.IfxSqli.executeCommit(IfxSqli.java:497)
at com.informix.jdbc.IfxSqliConnect.commit(IfxSqliConnect.java: 1964)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at nl.knowledgeplaza.util.jdbc.Connection.invoke(Connection.jav a:112)
at $Proxy0.commit(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at nl.reinders.jdbc.ReindersInformixConnection.invoke(ReindersI nformixConnection.java:66)
at $Proxy2.commit(Unknown Source)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicCommitTransaction(DatabaseAccessor.java:412)
... 13 more
Caused by: java.sql.SQLException
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:4 07)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3767)
... 30 more


Even though a remove operation was performed on Deliverylinenr 57253, the SQL does an update. I have delayed constraints, so the exception does not occur immediately. batchbuyorderline otoh is removed.
WindowsXP, Eclipselink 2.0.2, Java 1.6.17, Informix 11.
Re: update when removed? [message #642109 is a reply to message #642037] Mon, 29 November 2010 21:12 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

The update to set the deliverynr =null will occure regardless of the delete due to you calling setDelivery(null). So I assume the problem is that the delete is occuring - if it is that the field is being nulled out, then setDelivery(null) should not be called.

Do any other entities have references to the removed lDeliveryline possibly with cascade persist or merge set on the relationship? For instance, if the lDeliveryline is not removed from the getDeliverylinesWhereIAmDelivery collection and it is set to cascade persist, this will cause it to 'undo' the delete operation - the remove will occur, but then the unmanaged/removed lDeliveryline will be found still referenced by the managed
lDelivery causing it to be persisted. Net effect, no change occurs.

Best Regards,
Chris
Previous Topic:EclipseLink's XML parser for JBoss
Next Topic:DTYPE Generated on ManyToMany Join?
Goto Forum:
  


Current Time: Thu Mar 28 23:38:40 GMT 2024

Powered by FUDForum. Page generated in 0.03960 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top