cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Willerding <awillerd...@itsurcom.com>
Subject Re: No object is registered in context with Id
Date Thu, 03 Mar 2016 20:37:41 GMT
I had to add newItem before the getObjectContext() to allow the program 
to compile and then unfortunately I'm getting the error below.  There 
shouldn't be any duplicate entries as this is the first record I'm 
attempting to insert for this particular project and contact.  The 
underlying project id is 9999 and the contact id is 1922 so I'm not sure 
what is generating the duplicate entry.



used by: java.sql.BatchUpdateException: Duplicate entry '2-9999-1922-1' 
for key 'U_ProjectContact'
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
     at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
     at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
     at com.mysql.jdbc.Util.getInstance(Util.java:387)
     at 
com.mysql.jdbc.SQLError.createBatchUpdateException(SQLError.java:1160)
     at 
com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1773)
     at 
com.mysql.jdbc.PreparedStatement.executeBatchInternal(PreparedStatement.java:1257)
     at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:959)
     at 
org.apache.cayenne.access.jdbc.BatchAction.runAsBatch(BatchAction.java:125)
     at 
org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:90)
     at 
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
     at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
     at 
org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:234)
     at 
org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
     at 
org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629)
     at 
org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
     at 
org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
     at 
org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
     at 
org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
     at 
org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:53)
     at 
org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
     at 
org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
     at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585)
     at 
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
     ... 4 more
Caused by: 
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: 
Duplicate entry '2-9999-1922-1' for key 'U_ProjectContact'
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
     at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
     at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
     at com.mysql.jdbc.Util.getInstance(Util.java:387)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:934)
     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3870)
     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)
     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)
     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)
     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2550)
     at 
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
     at 
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
     at 
com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1751)
     ... 22 more


On 03/03/16 11:50 AM, dollj@xsinet.co.za wrote:
> Change the line that throws the exception --> newItem.setContact(item);
> to:  newItem.setContact( getObjectContext().localObject( item ) );
>
>
> -----Original Message----- From: Andrew Willerding
> Sent: Thursday, March 3, 2016 4:16 PM
> To: user@cayenne.apache.org
> Subject: Re: No object is registered in context with Id
>
> Here's the rest of the stack.
>
> 2016-03-03,09:05:44:433,ERROR,[Thread-15],,'com.callistacti.vaadinLib.IWindowEditBase'

>
> ERROR:ObservableComponent Error processing observer's update code.
> Observer==>class
> com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException:

>
> [v.4.0.M3 Feb 08 2016 17:09:41] No object is registered in context with
> Id <ObjectId:Contact, ContactID=1922>
>     at
> org.apache.cayenne.access.ObjectStore.registerDiff(ObjectStore.java:162)
>     at
> org.apache.cayenne.access.ObjectStore.arcCreated(ObjectStore.java:974)
>     at
> org.apache.cayenne.util.ObjectContextGraphAction.handleArcPropertyChange(ObjectContextGraphAction.java:88)

>
>     at
> org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:65)

>
>     at 
> org.apache.cayenne.BaseContext.propertyChanged(BaseContext.java:460)
>     at
> org.apache.cayenne.CayenneDataObject.addToManyTarget(CayenneDataObject.java:248) 
>
>     at
> org.apache.cayenne.CayenneDataObject.setReverseRelationship(CayenneDataObject.java:417)

>
>     at
> org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:372) 
>
>     at
> com.itsurcom.bluecranex.database.auto._ProjectContact.setContact(_ProjectContact.java:44)

>
>
> The reason I was setting all the objects to use the same ObjectContext
> was that the objects themselves are setup in multiple threads and I was
> getting ObjectContext errors.
>
> Here is the error I was trying to get around.
>
> 2016-03-03,09:12:20:135,ERROR,[Thread-25],,'com.callistacti.vaadinLib.IWindowEditBase'

>
> ERROR:ObservableComponent Error processing observer's update code.
> Observer==>class
> com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException:

>
> [v.4.0.M3 Feb 08 2016 17:09:41] Cannot set object as destination of
> relationship contact because it is in a different ObjectContext
>     at
> org.apache.cayenne.CayenneDataObject.willConnect(CayenneDataObject.java:399) 
>
>     at
> org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:355) 
>
>     at
> com.itsurcom.bluecranex.database.auto._ProjectContact.setContact(_ProjectContact.java:44)

>
>
> Using this code...
>
>                 ObjectContext oc = UI.getObjectContext();
>                 int addItemCount = 0;
>                 for (Contact item : list) {
>
>                     ProjectContact newItem =
> oc.newObject(ProjectContact.class);
>
>                     //project.setObjectContext(oc);
>                     //project.getCompany().setObjectContext(oc);
>                     newItem.setCompany(project.getCompany());
>                     //item.setObjectContext(oc);
>
> exception-->newItem.setContact(item);
>                     newItem.setProject(project);
> newItem.setPrimeContact(ProjectContact.Type.NON_PRIME.getCode());
>                     addItemCount++;
>                 }
>             oc.commitChanges();
>
>
>
> On 03/03/16 06:32 AM, Andrus Adamchik wrote:
>> Hi Andrew,
>>
>> You don't show the relevant stack, so I can only guess. But I find 
>> the following code suspect:
>>
>>>     project.setObjectContext(oc);
>>>     project.getCompany().setObjectContext(oc);
>> Setting ObjectContext explicitly on Persistent objects is never a 
>> good idea. Object should stay in the ObjectContext it was created in 
>> or fetched from). Any specific reason why you are doing that?
>>
>> Andrus
>>
>>
>>
>>> On Mar 3, 2016, at 6:15 AM, Andrew Willerding 
>>> <awillerding@itsurcom.com> wrote:
>>>
>>> I am stuck on exactly what this message means and how to correct the 
>>> situation.
>>>
>>> Here are my table relationships.
>>>
>>> Project               ProjectContact         Contact
>>> ---------               -------------------- ----------
>>> ProjectID <--->     ProjectID
>>>                               ContactID    <---> ContactID
>>>
>>> Here is my code.
>>>
>>>                 ObjectContext oc = UI.getObjectContext();
>>>                 for (Contact item : list) {
>>>                     ProjectContact newItem = 
>>> oc.newObject(ProjectContact.class);
>>>                     project.setObjectContext(oc);
>>>                     project.getCompany().setObjectContext(oc);
>>>                     newItem.setCompany(project.getCompany());
>>>                     item.setObjectContext(oc);
>>> exception->newItem.setContact(item);
>>>                     newItem.setProject(project);
>>> newItem.setPrimeContact(ProjectContact.Type.NON_PRIME.getCode());
>>>                     addItemCount++;
>>>
>>> Here's the exception that is thrown when the 
>>> newItem.setContact(item) is executed.
>>>
>>> 2016-03-02,22:00:25:587,ERROR,[Thread-83],,'com.callistacti.vaadinLib.IWindowEditBase'

>>> ERROR:ObservableComponent Error processing observer's update code. 
>>> Observer==>class 
>>> com.itsurcom.bluecranex.GUI.Panels.PanelProjectContacts::org.apache.cayenne.CayenneRuntimeException:

>>> [v.4.0.M3 Feb 08 2016 17:09:41] No object is registered in context 
>>> with Id <ObjectId:Contact, ContactID=1170>
>>>
>


Mime
View raw message