You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by cghersi <cr...@abodata.com> on 2012/03/05 16:57:27 UTC

Temporary ID hasn't been replaced on commit

Hi all,

I'm using Cayenne 3.0. For more then 1 year we hadn't got any issue; now,
suddenly, sometimes it appears a strange Exception: "Temporary ID hasn't
been replaced on commit".
It appears on an object whose table has an autogenerated PK.

What can I do to avoid such a situation?

Thank you very much.
Best
cghersi


--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801043.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Robert,

 

thank you for the hint: using one data context per request solved the problem!

 

Up to now, I didn’t encountered any more this issue.

 

Thanks to all for the help!

Best

cghersi

 

From: Robert Zeigler-6 [via Cayenne] [mailto:ml-node+s195n3818950h82@n3.nabble.com] 
Sent: lunedì 12 marzo 2012 12:18
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 

Are you using one datacontext for the entire application? 

Generally, you want one datacontext per user, or even one datacontext per request, depending on your use-case. 

The exception is a "read-only" data context for data that doesn't typically change (lookup tables, for instance). 

Robert 

On Mar 12, 2012, at 3/126:10 AM , cghersi wrote: 


> Update: I think I found the real source of the problem. 
> 
> When I commit the just created object, I use the method context.commitChanges() that saves ALL my persistent objects. If in another thread I’m creating another persistent object in the meanwhile, such object is saved with the partial information just added. 
> 
> e.g. 
> 
> in the first thread: 
> 
> MyPerstObject1 newObj = context.get().newObject(MyPerstObject1.class); 
> 
> newObj.setField1(“valueForField1”); 
> 
> newObj.setField2(“valueForField2”); 
> 
> newObj.setField3(“valueForField3”); 
> 
> newObj.setField4(“valueForField4”); 
> 
> context.commitChanges(); 
> 
> 
> 
> in another thread: 
> 
> MyPerstObject2 newObj = context.get().newObject(MyPerstObject2.class); //there’s a “Id” PK field AUTO_INCREMENT (MySQL) 
> 
> newObj.setField1(“valueForField1”); 
> 
> newObj.setField2(“valueForField2”); 
> 
> newObj.setField3(“valueForField3”); 
> 
> newObj.setField4(“valueForField4”); 
> 
> newObj.setField5(“valueForField5”); 
> 
> newObj.setField6(“valueForField6”); 
> 
> context.commitChanges(); 
> 
> 
> 
> Now, if the commitChanges() in the first thread is invoked e.g. when I performing newObj.setField3(“valueForField3”); in the another thread, the newObj of type MyPerstObject2 should be saved without fields 4,5,6 filled, resulting in ValidationException in the first thread (given that field 4, 5 and/or 6 are mandatory). 
> 
> I also tried to make the fields 4,5,6 optional, but in this case another exception occurs: 
> 
> org.apache.cayenne.access.OptimisticLockException: [v.3.0 Apr 26 2010 09:59:17] Optimistic Lock Failure, SQL: [UPDATE MyPerstObject2 SET Field1 = ?, Field2 = ?, Field3 = ?, Field4 = ?, Field5 = ?, Field6 = ? WHERE Id IS NULL], WHERE clause bindings: [Id=NULL] 
> 
> at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:232) 
> 
> at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:91) 
> 
> at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87) 
> 
> at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269) 
> 
> at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:226) 
> 
> at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:144) 
> 
> at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:824) 
> 
> at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:791) 
> 
> at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850) 
> 
> at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:788) 
> 
> at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1106) 
> 
> at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045) 
> 
> 
> 
> 
> 
> This issue is really driving me crazy!! 
> 
> Please, let me know what I’m doing wrong… 
> 
> 
> 
> Thank you very much 
> 
> Best 
> 
> cghersi 
> 
> 
> 
> 
> 
> From: Cristiano Ghersi [mailto:[hidden email]] 
> Sent: lunedì 12 marzo 2012 10:01 
> To: 'Andrus Adamchik [via Cayenne]' 
> Subject: RE: Temporary ID hasn't been replaced on commit 
> 
> 
> 
> OK, but this is exactly the method that causes the exception L 
> 
> 
> 
> Now I’m trying to resolve the problem at the very top, adding a synchronization block to all my context.commitChanges(): this solution, anyway, seems to be too drastic for my application: is there a way to commit changes related only to a single table? 
> 
> 
> 
> Thank you very much. 
> 
> Best 
> 
> cghersi 
> 
> 
> 
> From: Andrus Adamchik [via Cayenne] [mailto:[hidden email]] 
> Sent: venerdì 9 marzo 2012 17:41 
> To: cghersi 
> Subject: Re: Temporary ID hasn't been replaced on commit 
> 
> 
> 
> Sorry this is Cayenne 3.1 API, and there is a typo :) 
> 
> 3.1: Cayenne.intPkForObject 
> 3.0: DataObjectUtils.intPkForObject 
> 
> On Mar 9, 2012, at 11:33 AM, cghersi wrote: 
> 
> 
>> Hi Andrus, 
>> 
>> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use? 
>> 
>> 
>> 
>> Thank you very much. 
>> 
>> Best 
>> 
>> cghersi 
>> 
>> 
>> 
>> From: Andrus Adamchik [via Cayenne] [mailto:[hidden email]] 
>> Sent: venerdì 9 marzo 2012 15:40 
>> To: cghersi 
>> Subject: Re: Temporary ID hasn't been replaced on commit 
>> 
>> 
>> 
>>> Is there any effective way to directly retrieve the ID of the just added 
>>> object after the context.commitChanges() invocation? 
>> 
>> After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 
>> 
>> Andrus 
>> 
>> On Mar 9, 2012, at 9:10 AM, cghersi wrote: 
>> 
>> 
>>> Hi all, perhaps I’ve understood something about the issue: 
>>> 
>>> Seems that the problem arises when I add a new object to the DB: just after 
>>> the insert, I need the autogenerated PK, and this seems to put in troubles 
>>> the method DataObjectUtils.intPKForObject(Persistent); 
>>> 
>>> Which sometimes throws the Exception in the subject. 
>>> 
>>> 
>>> 
>>> Is there any effective way to directly retrieve the ID of the just added 
>>> object after the context.commitChanges() invocation? 
>>> 
>>> 
>>> 
>>> Thank you very much for your help. 
>>> 
>>> 
>>> 
>>> Best 
>>> 
>>> cghersi 
>>> 
>>> 
>>> 
>>> From: cghersi [via Cayenne] [mailto:[hidden email]] 
>>> Sent: mercoledì 7 marzo 2012 09:43 
>>> To: cghersi 
>>> Subject: Re: Temporary ID hasn't been replaced on commit 
>>> 
>>> 
>>> 
>>> Hi Andrus, 
>>> 
>>> here there's the code that I use to save my object: 
>>> 
>>>      private AtomicReference<DataContext> context = new 
>>> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
>>> ext()); 
>>> 
>>>      public Network GetNetworkByPK(Integer pkID) { 
>>>              ObjectId id = new ObjectId(Network.class.getSimpleName(), 
>>> Network.ID_PK_COLUMN, pkID); 
>>> 
>>>              // this constructor implicitly uses "CACHE_REFRESH" policy, 
>>> so a fresh object will be returned 
>>>              ObjectIdQuery query = new ObjectIdQuery(id); 
>>>              return 
>>> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>>>      } 
>>> 
>>>      public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>>>              Expression qualifier = 
>>> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>>>              List<PhysicalNode> list = query(qualifier, 
>>> PhysicalNode.class); 
>>> 
>>>              //there can be only a single result from this query: 
>>>              return list.get(0); 
>>>      } 
>>> 
>>>      public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
>>> byte[] nsap, int netId, short type, 
>>>                      boolean isOnline, String defaultLabel){ 
>>> 
>>>              PhysicalNode pn=null; 
>>>              Network n = GetNetworkByPK(netId); 
>>>              if(n!=null){ 
>>>                      pn = GetPhysicalNodeByMac(macAddr); 
>>>                      if(pn==null){ 
>>>                              pn = createNewObj(PhysicalNode.class); 
>>>                              pn.setMacAddress(macAddr); 
>>>                              pn.setLabel(defaultLabel); 
>>>                              pn.setCoordX((double)-1); 
>>>                              pn.setCoordY((double)-1); 
>>>                              pn.setCoordZ((double)-1); 
>>>                              pn.setCreation((new Date()).getTime()); 
>>>                      } 
>>>                      pn.setNetwork(n); 
>>>                      pn.setNsap(nsap); 
>>>                      pn.setType(type); 
>>>                      pn.setIsOnline(isOnline); 
>>>                      CommitObjects(PhysicalNode.class); 
>>>              } 
>>>              else{ 
>>>                      throw new ValidationException("Network not in DB"); 
>>>              } 
>>>              return pn; 
>>>      } 
>>> 
>>> The problem is not systematic, but may occur with randomness if I force the 
>>> DB to add a great number of PhysicalNode objects in a little time window. 
>>> 
>>> Please, let me know if you have any idea! 
>>> 
>>> Thank you very much 
>>> Best 
>>> cghersi 
>>> 
>>> _____   
>> 
>> 
>> 
>> 
>> 
>> _____   
>> 
>> If you reply to this email, your message will be added to the discussion below: 
>> 
>> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html  
>> 
>> To unsubscribe from Temporary ID hasn't been replaced on commit, click here < . 
>> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
>> 
>> 
>> 
>> -- 
>> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
>> Sent from the Cayenne - User mailing list archive at Nabble.com. 
> 
> 
> 
>  _____   
> 
> If you reply to this email, your message will be added to the discussion below: 
> 
> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813176.html  
> 
> To unsubscribe from Temporary ID hasn't been replaced on commit, click here < . 
> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
> 
> 
> 
> -- 
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3818939.html
> Sent from the Cayenne - User mailing list archive at Nabble.com. 





  _____  

If you reply to this email, your message will be added to the discussion below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3818950.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
 <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3831292.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Robert Zeigler <ro...@roxanemy.com>.
Are you using one datacontext for the entire application?

Generally, you want one datacontext per user, or even one datacontext per request, depending on your use-case.

The exception is a "read-only" data context for data that doesn't typically change (lookup tables, for instance).

Robert

On Mar 12, 2012, at 3/126:10 AM , cghersi wrote:

> Update: I think I found the real source of the problem.
> 
> When I commit the just created object, I use the method context.commitChanges() that saves ALL my persistent objects. If in another thread I’m creating another persistent object in the meanwhile, such object is saved with the partial information just added.
> 
> e.g.
> 
> in the first thread:
> 
> MyPerstObject1 newObj = context.get().newObject(MyPerstObject1.class);
> 
> newObj.setField1(“valueForField1”);
> 
> newObj.setField2(“valueForField2”);
> 
> newObj.setField3(“valueForField3”);
> 
> newObj.setField4(“valueForField4”);
> 
> context.commitChanges();
> 
> 
> 
> in another thread:
> 
> MyPerstObject2 newObj = context.get().newObject(MyPerstObject2.class); //there’s a “Id” PK field AUTO_INCREMENT (MySQL)
> 
> newObj.setField1(“valueForField1”);
> 
> newObj.setField2(“valueForField2”);
> 
> newObj.setField3(“valueForField3”);
> 
> newObj.setField4(“valueForField4”);
> 
> newObj.setField5(“valueForField5”);
> 
> newObj.setField6(“valueForField6”);
> 
> context.commitChanges();
> 
> 
> 
> Now, if the commitChanges() in the first thread is invoked e.g. when I performing newObj.setField3(“valueForField3”); in the another thread, the newObj of type MyPerstObject2 should be saved without fields 4,5,6 filled, resulting in ValidationException in the first thread (given that field 4, 5 and/or 6 are mandatory).
> 
> I also tried to make the fields 4,5,6 optional, but in this case another exception occurs: 
> 
> org.apache.cayenne.access.OptimisticLockException: [v.3.0 Apr 26 2010 09:59:17] Optimistic Lock Failure, SQL: [UPDATE MyPerstObject2 SET Field1 = ?, Field2 = ?, Field3 = ?, Field4 = ?, Field5 = ?, Field6 = ? WHERE Id IS NULL], WHERE clause bindings: [Id=NULL]
> 
> at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:232)
> 
> at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:91)
> 
> at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
> 
> at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)
> 
> at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:226)
> 
> at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:144)
> 
> at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:824)
> 
> at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:791)
> 
> at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
> 
> at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:788)
> 
> at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1106)
> 
> at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)
> 
> 
> 
> 
> 
> This issue is really driving me crazy!!
> 
> Please, let me know what I’m doing wrong…
> 
> 
> 
> Thank you very much
> 
> Best
> 
> cghersi
> 
> 
> 
> 
> 
> From: Cristiano Ghersi [mailto:cristiano.ghersi@abodata.com] 
> Sent: lunedì 12 marzo 2012 10:01
> To: 'Andrus Adamchik [via Cayenne]'
> Subject: RE: Temporary ID hasn't been replaced on commit
> 
> 
> 
> OK, but this is exactly the method that causes the exception L
> 
> 
> 
> Now I’m trying to resolve the problem at the very top, adding a synchronization block to all my context.commitChanges(): this solution, anyway, seems to be too drastic for my application: is there a way to commit changes related only to a single table?
> 
> 
> 
> Thank you very much.
> 
> Best
> 
> cghersi
> 
> 
> 
> From: Andrus Adamchik [via Cayenne] [mailto:ml-node+s195n3813176h88@n3.nabble.com] 
> Sent: venerdì 9 marzo 2012 17:41
> To: cghersi
> Subject: Re: Temporary ID hasn't been replaced on commit
> 
> 
> 
> Sorry this is Cayenne 3.1 API, and there is a typo :) 
> 
> 3.1: Cayenne.intPkForObject 
> 3.0: DataObjectUtils.intPkForObject 
> 
> On Mar 9, 2012, at 11:33 AM, cghersi wrote: 
> 
> 
>> Hi Andrus, 
>> 
>> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use? 
>> 
>> 
>> 
>> Thank you very much. 
>> 
>> Best 
>> 
>> cghersi 
>> 
>> 
>> 
>> From: Andrus Adamchik [via Cayenne] [mailto:[hidden email]] 
>> Sent: venerdì 9 marzo 2012 15:40 
>> To: cghersi 
>> Subject: Re: Temporary ID hasn't been replaced on commit 
>> 
>> 
>> 
>>> Is there any effective way to directly retrieve the ID of the just added 
>>> object after the context.commitChanges() invocation? 
>> 
>> After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 
>> 
>> Andrus 
>> 
>> On Mar 9, 2012, at 9:10 AM, cghersi wrote: 
>> 
>> 
>>> Hi all, perhaps I’ve understood something about the issue: 
>>> 
>>> Seems that the problem arises when I add a new object to the DB: just after 
>>> the insert, I need the autogenerated PK, and this seems to put in troubles 
>>> the method DataObjectUtils.intPKForObject(Persistent); 
>>> 
>>> Which sometimes throws the Exception in the subject. 
>>> 
>>> 
>>> 
>>> Is there any effective way to directly retrieve the ID of the just added 
>>> object after the context.commitChanges() invocation? 
>>> 
>>> 
>>> 
>>> Thank you very much for your help. 
>>> 
>>> 
>>> 
>>> Best 
>>> 
>>> cghersi 
>>> 
>>> 
>>> 
>>> From: cghersi [via Cayenne] [mailto:[hidden email]] 
>>> Sent: mercoledì 7 marzo 2012 09:43 
>>> To: cghersi 
>>> Subject: Re: Temporary ID hasn't been replaced on commit 
>>> 
>>> 
>>> 
>>> Hi Andrus, 
>>> 
>>> here there's the code that I use to save my object: 
>>> 
>>>      private AtomicReference<DataContext> context = new 
>>> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
>>> ext()); 
>>> 
>>>      public Network GetNetworkByPK(Integer pkID) { 
>>>              ObjectId id = new ObjectId(Network.class.getSimpleName(), 
>>> Network.ID_PK_COLUMN, pkID); 
>>> 
>>>              // this constructor implicitly uses "CACHE_REFRESH" policy, 
>>> so a fresh object will be returned 
>>>              ObjectIdQuery query = new ObjectIdQuery(id); 
>>>              return 
>>> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>>>      } 
>>> 
>>>      public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>>>              Expression qualifier = 
>>> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>>>              List<PhysicalNode> list = query(qualifier, 
>>> PhysicalNode.class); 
>>> 
>>>              //there can be only a single result from this query: 
>>>              return list.get(0); 
>>>      } 
>>> 
>>>      public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
>>> byte[] nsap, int netId, short type, 
>>>                      boolean isOnline, String defaultLabel){ 
>>> 
>>>              PhysicalNode pn=null; 
>>>              Network n = GetNetworkByPK(netId); 
>>>              if(n!=null){ 
>>>                      pn = GetPhysicalNodeByMac(macAddr); 
>>>                      if(pn==null){ 
>>>                              pn = createNewObj(PhysicalNode.class); 
>>>                              pn.setMacAddress(macAddr); 
>>>                              pn.setLabel(defaultLabel); 
>>>                              pn.setCoordX((double)-1); 
>>>                              pn.setCoordY((double)-1); 
>>>                              pn.setCoordZ((double)-1); 
>>>                              pn.setCreation((new Date()).getTime()); 
>>>                      } 
>>>                      pn.setNetwork(n); 
>>>                      pn.setNsap(nsap); 
>>>                      pn.setType(type); 
>>>                      pn.setIsOnline(isOnline); 
>>>                      CommitObjects(PhysicalNode.class); 
>>>              } 
>>>              else{ 
>>>                      throw new ValidationException("Network not in DB"); 
>>>              } 
>>>              return pn; 
>>>      } 
>>> 
>>> The problem is not systematic, but may occur with randomness if I force the 
>>> DB to add a great number of PhysicalNode objects in a little time window. 
>>> 
>>> Please, let me know if you have any idea! 
>>> 
>>> Thank you very much 
>>> Best 
>>> cghersi 
>>> 
>>> _____   
>> 
>> 
>> 
>> 
>> 
>> _____   
>> 
>> If you reply to this email, your message will be added to the discussion below: 
>> 
>> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html  
>> 
>> To unsubscribe from Temporary ID hasn't been replaced on commit, click here < . 
>> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
>> 
>> 
>> 
>> -- 
>> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
>> Sent from the Cayenne - User mailing list archive at Nabble.com. 
> 
> 
> 
>  _____  
> 
> If you reply to this email, your message will be added to the discussion below:
> 
> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813176.html 
> 
> To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
> 
> 
> 
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3818939.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.


RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Update: I think I found the real source of the problem.

When I commit the just created object, I use the method context.commitChanges() that saves ALL my persistent objects. If in another thread I’m creating another persistent object in the meanwhile, such object is saved with the partial information just added.

e.g.

in the first thread:

MyPerstObject1 newObj = context.get().newObject(MyPerstObject1.class);

newObj.setField1(“valueForField1”);

newObj.setField2(“valueForField2”);

newObj.setField3(“valueForField3”);

newObj.setField4(“valueForField4”);

context.commitChanges();

 

in another thread:

MyPerstObject2 newObj = context.get().newObject(MyPerstObject2.class); //there’s a “Id” PK field AUTO_INCREMENT (MySQL)

newObj.setField1(“valueForField1”);

newObj.setField2(“valueForField2”);

newObj.setField3(“valueForField3”);

newObj.setField4(“valueForField4”);

newObj.setField5(“valueForField5”);

newObj.setField6(“valueForField6”);

context.commitChanges();

 

Now, if the commitChanges() in the first thread is invoked e.g. when I performing newObj.setField3(“valueForField3”); in the another thread, the newObj of type MyPerstObject2 should be saved without fields 4,5,6 filled, resulting in ValidationException in the first thread (given that field 4, 5 and/or 6 are mandatory).

I also tried to make the fields 4,5,6 optional, but in this case another exception occurs: 

org.apache.cayenne.access.OptimisticLockException: [v.3.0 Apr 26 2010 09:59:17] Optimistic Lock Failure, SQL: [UPDATE MyPerstObject2 SET Field1 = ?, Field2 = ?, Field3 = ?, Field4 = ?, Field5 = ?, Field6 = ? WHERE Id IS NULL], WHERE clause bindings: [Id=NULL]

at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:232)

at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:91)

at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)

at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)

at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:226)

at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:144)

at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:824)

at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:791)

at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)

at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:788)

at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1106)

at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)

 

 

This issue is really driving me crazy!!

Please, let me know what I’m doing wrong…

 

Thank you very much

Best

cghersi

 

 

From: Cristiano Ghersi [mailto:cristiano.ghersi@abodata.com] 
Sent: lunedì 12 marzo 2012 10:01
To: 'Andrus Adamchik [via Cayenne]'
Subject: RE: Temporary ID hasn't been replaced on commit

 

OK, but this is exactly the method that causes the exception L

 

Now I’m trying to resolve the problem at the very top, adding a synchronization block to all my context.commitChanges(): this solution, anyway, seems to be too drastic for my application: is there a way to commit changes related only to a single table?

 

Thank you very much.

Best

cghersi

 

From: Andrus Adamchik [via Cayenne] [mailto:ml-node+s195n3813176h88@n3.nabble.com] 
Sent: venerdì 9 marzo 2012 17:41
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 

Sorry this is Cayenne 3.1 API, and there is a typo :) 

3.1: Cayenne.intPkForObject 
3.0: DataObjectUtils.intPkForObject 

On Mar 9, 2012, at 11:33 AM, cghersi wrote: 


> Hi Andrus, 
> 
> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use? 
> 
> 
> 
> Thank you very much. 
> 
> Best 
> 
> cghersi 
> 
> 
> 
> From: Andrus Adamchik [via Cayenne] [mailto:[hidden email]] 
> Sent: venerdì 9 marzo 2012 15:40 
> To: cghersi 
> Subject: Re: Temporary ID hasn't been replaced on commit 
> 
> 
> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
> 
> After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 
> 
> Andrus 
> 
> On Mar 9, 2012, at 9:10 AM, cghersi wrote: 
> 
> 
>> Hi all, perhaps I’ve understood something about the issue: 
>> 
>> Seems that the problem arises when I add a new object to the DB: just after 
>> the insert, I need the autogenerated PK, and this seems to put in troubles 
>> the method DataObjectUtils.intPKForObject(Persistent); 
>> 
>> Which sometimes throws the Exception in the subject. 
>> 
>> 
>> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
>> 
>> 
>> 
>> Thank you very much for your help. 
>> 
>> 
>> 
>> Best 
>> 
>> cghersi 
>> 
>> 
>> 
>> From: cghersi [via Cayenne] [mailto:[hidden email]] 
>> Sent: mercoledì 7 marzo 2012 09:43 
>> To: cghersi 
>> Subject: Re: Temporary ID hasn't been replaced on commit 
>> 
>> 
>> 
>> Hi Andrus, 
>> 
>> here there's the code that I use to save my object: 
>> 
>>       private AtomicReference<DataContext> context = new 
>> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
>> ext()); 
>> 
>>       public Network GetNetworkByPK(Integer pkID) { 
>>               ObjectId id = new ObjectId(Network.class.getSimpleName(), 
>> Network.ID_PK_COLUMN, pkID); 
>> 
>>               // this constructor implicitly uses "CACHE_REFRESH" policy, 
>> so a fresh object will be returned 
>>               ObjectIdQuery query = new ObjectIdQuery(id); 
>>               return 
>> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>>       } 
>> 
>>       public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>>               Expression qualifier = 
>> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>>               List<PhysicalNode> list = query(qualifier, 
>> PhysicalNode.class); 
>> 
>>               //there can be only a single result from this query: 
>>               return list.get(0); 
>>       } 
>> 
>>       public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
>> byte[] nsap, int netId, short type, 
>>                       boolean isOnline, String defaultLabel){ 
>> 
>>               PhysicalNode pn=null; 
>>               Network n = GetNetworkByPK(netId); 
>>               if(n!=null){ 
>>                       pn = GetPhysicalNodeByMac(macAddr); 
>>                       if(pn==null){ 
>>                               pn = createNewObj(PhysicalNode.class); 
>>                               pn.setMacAddress(macAddr); 
>>                               pn.setLabel(defaultLabel); 
>>                               pn.setCoordX((double)-1); 
>>                               pn.setCoordY((double)-1); 
>>                               pn.setCoordZ((double)-1); 
>>                               pn.setCreation((new Date()).getTime()); 
>>                       } 
>>                       pn.setNetwork(n); 
>>                       pn.setNsap(nsap); 
>>                       pn.setType(type); 
>>                       pn.setIsOnline(isOnline); 
>>                       CommitObjects(PhysicalNode.class); 
>>               } 
>>               else{ 
>>                       throw new ValidationException("Network not in DB"); 
>>               } 
>>               return pn; 
>>       } 
>> 
>> The problem is not systematic, but may occur with randomness if I force the 
>> DB to add a great number of PhysicalNode objects in a little time window. 
>> 
>> Please, let me know if you have any idea! 
>> 
>> Thank you very much 
>> Best 
>> cghersi 
>> 
>> _____   
> 
> 
> 
> 
> 
>  _____   
> 
> If you reply to this email, your message will be added to the discussion below: 
> 
> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html  
> 
> To unsubscribe from Temporary ID hasn't been replaced on commit, click here < . 
> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
> 
> 
> 
> -- 
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
> Sent from the Cayenne - User mailing list archive at Nabble.com. 

 

  _____  

If you reply to this email, your message will be added to the discussion below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813176.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
 <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3818939.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
OK, but this is exactly the method that causes the exception L

 

Now I’m trying to resolve the problem at the very top, adding a synchronization block to all my context.commitChanges(): this solution, anyway, seems to be too drastic for my application: is there a way to commit changes related only to a single table?

 

Thank you very much.

Best

cghersi

 

From: Andrus Adamchik [via Cayenne] [mailto:ml-node+s195n3813176h88@n3.nabble.com] 
Sent: venerdì 9 marzo 2012 17:41
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 

Sorry this is Cayenne 3.1 API, and there is a typo :) 

3.1: Cayenne.intPkForObject 
3.0: DataObjectUtils.intPkForObject 

On Mar 9, 2012, at 11:33 AM, cghersi wrote: 


> Hi Andrus, 
> 
> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use? 
> 
> 
> 
> Thank you very much. 
> 
> Best 
> 
> cghersi 
> 
> 
> 
> From: Andrus Adamchik [via Cayenne] [mailto:[hidden email]] 
> Sent: venerdì 9 marzo 2012 15:40 
> To: cghersi 
> Subject: Re: Temporary ID hasn't been replaced on commit 
> 
> 
> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
> 
> After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 
> 
> Andrus 
> 
> On Mar 9, 2012, at 9:10 AM, cghersi wrote: 
> 
> 
>> Hi all, perhaps I’ve understood something about the issue: 
>> 
>> Seems that the problem arises when I add a new object to the DB: just after 
>> the insert, I need the autogenerated PK, and this seems to put in troubles 
>> the method DataObjectUtils.intPKForObject(Persistent); 
>> 
>> Which sometimes throws the Exception in the subject. 
>> 
>> 
>> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
>> 
>> 
>> 
>> Thank you very much for your help. 
>> 
>> 
>> 
>> Best 
>> 
>> cghersi 
>> 
>> 
>> 
>> From: cghersi [via Cayenne] [mailto:[hidden email]] 
>> Sent: mercoledì 7 marzo 2012 09:43 
>> To: cghersi 
>> Subject: Re: Temporary ID hasn't been replaced on commit 
>> 
>> 
>> 
>> Hi Andrus, 
>> 
>> here there's the code that I use to save my object: 
>> 
>>       private AtomicReference<DataContext> context = new 
>> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
>> ext()); 
>> 
>>       public Network GetNetworkByPK(Integer pkID) { 
>>               ObjectId id = new ObjectId(Network.class.getSimpleName(), 
>> Network.ID_PK_COLUMN, pkID); 
>> 
>>               // this constructor implicitly uses "CACHE_REFRESH" policy, 
>> so a fresh object will be returned 
>>               ObjectIdQuery query = new ObjectIdQuery(id); 
>>               return 
>> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>>       } 
>> 
>>       public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>>               Expression qualifier = 
>> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>>               List<PhysicalNode> list = query(qualifier, 
>> PhysicalNode.class); 
>> 
>>               //there can be only a single result from this query: 
>>               return list.get(0); 
>>       } 
>> 
>>       public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
>> byte[] nsap, int netId, short type, 
>>                       boolean isOnline, String defaultLabel){ 
>> 
>>               PhysicalNode pn=null; 
>>               Network n = GetNetworkByPK(netId); 
>>               if(n!=null){ 
>>                       pn = GetPhysicalNodeByMac(macAddr); 
>>                       if(pn==null){ 
>>                               pn = createNewObj(PhysicalNode.class); 
>>                               pn.setMacAddress(macAddr); 
>>                               pn.setLabel(defaultLabel); 
>>                               pn.setCoordX((double)-1); 
>>                               pn.setCoordY((double)-1); 
>>                               pn.setCoordZ((double)-1); 
>>                               pn.setCreation((new Date()).getTime()); 
>>                       } 
>>                       pn.setNetwork(n); 
>>                       pn.setNsap(nsap); 
>>                       pn.setType(type); 
>>                       pn.setIsOnline(isOnline); 
>>                       CommitObjects(PhysicalNode.class); 
>>               } 
>>               else{ 
>>                       throw new ValidationException("Network not in DB"); 
>>               } 
>>               return pn; 
>>       } 
>> 
>> The problem is not systematic, but may occur with randomness if I force the 
>> DB to add a great number of PhysicalNode objects in a little time window. 
>> 
>> Please, let me know if you have any idea! 
>> 
>> Thank you very much 
>> Best 
>> cghersi 
>> 
>> _____   
> 
> 
> 
> 
> 
>  _____   
> 
> If you reply to this email, your message will be added to the discussion below: 
> 
> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html  
> 
> To unsubscribe from Temporary ID hasn't been replaced on commit, click here < . 
> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> &id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
> 
> 
> 
> -- 
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
> Sent from the Cayenne - User mailing list archive at Nabble.com. 





  _____  

If you reply to this email, your message will be added to the discussion below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813176.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
 <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3818733.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
Sorry this is Cayenne 3.1 API, and there is a typo :)

3.1: Cayenne.intPkForObject
3.0: DataObjectUtils.intPkForObject

On Mar 9, 2012, at 11:33 AM, cghersi wrote:

> Hi Andrus, 
> 
> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use?
> 
> 
> 
> Thank you very much.
> 
> Best
> 
> cghersi
> 
> 
> 
> From: Andrus Adamchik [via Cayenne] [mailto:ml-node+s195n3812833h55@n3.nabble.com] 
> Sent: venerdì 9 marzo 2012 15:40
> To: cghersi
> Subject: Re: Temporary ID hasn't been replaced on commit
> 
> 
> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
> 
> After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 
> 
> Andrus 
> 
> On Mar 9, 2012, at 9:10 AM, cghersi wrote: 
> 
> 
>> Hi all, perhaps I’ve understood something about the issue: 
>> 
>> Seems that the problem arises when I add a new object to the DB: just after 
>> the insert, I need the autogenerated PK, and this seems to put in troubles 
>> the method DataObjectUtils.intPKForObject(Persistent); 
>> 
>> Which sometimes throws the Exception in the subject. 
>> 
>> 
>> 
>> Is there any effective way to directly retrieve the ID of the just added 
>> object after the context.commitChanges() invocation? 
>> 
>> 
>> 
>> Thank you very much for your help. 
>> 
>> 
>> 
>> Best 
>> 
>> cghersi 
>> 
>> 
>> 
>> From: cghersi [via Cayenne] [mailto:[hidden email]] 
>> Sent: mercoledì 7 marzo 2012 09:43 
>> To: cghersi 
>> Subject: Re: Temporary ID hasn't been replaced on commit 
>> 
>> 
>> 
>> Hi Andrus, 
>> 
>> here there's the code that I use to save my object: 
>> 
>>       private AtomicReference<DataContext> context = new 
>> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
>> ext()); 
>> 
>>       public Network GetNetworkByPK(Integer pkID) { 
>>               ObjectId id = new ObjectId(Network.class.getSimpleName(), 
>> Network.ID_PK_COLUMN, pkID); 
>> 
>>               // this constructor implicitly uses "CACHE_REFRESH" policy, 
>> so a fresh object will be returned 
>>               ObjectIdQuery query = new ObjectIdQuery(id); 
>>               return 
>> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>>       } 
>> 
>>       public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>>               Expression qualifier = 
>> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>>               List<PhysicalNode> list = query(qualifier, 
>> PhysicalNode.class); 
>> 
>>               //there can be only a single result from this query: 
>>               return list.get(0); 
>>       } 
>> 
>>       public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
>> byte[] nsap, int netId, short type, 
>>                       boolean isOnline, String defaultLabel){ 
>> 
>>               PhysicalNode pn=null; 
>>               Network n = GetNetworkByPK(netId); 
>>               if(n!=null){ 
>>                       pn = GetPhysicalNodeByMac(macAddr); 
>>                       if(pn==null){ 
>>                               pn = createNewObj(PhysicalNode.class); 
>>                               pn.setMacAddress(macAddr); 
>>                               pn.setLabel(defaultLabel); 
>>                               pn.setCoordX((double)-1); 
>>                               pn.setCoordY((double)-1); 
>>                               pn.setCoordZ((double)-1); 
>>                               pn.setCreation((new Date()).getTime()); 
>>                       } 
>>                       pn.setNetwork(n); 
>>                       pn.setNsap(nsap); 
>>                       pn.setType(type); 
>>                       pn.setIsOnline(isOnline); 
>>                       CommitObjects(PhysicalNode.class); 
>>               } 
>>               else{ 
>>                       throw new ValidationException("Network not in DB"); 
>>               } 
>>               return pn; 
>>       } 
>> 
>> The problem is not systematic, but may occur with randomness if I force the 
>> DB to add a great number of PhysicalNode objects in a little time window. 
>> 
>> Please, let me know if you have any idea! 
>> 
>> Thank you very much 
>> Best 
>> cghersi 
>> 
>> _____   
> 
> 
> 
> 
> 
>  _____  
> 
> If you reply to this email, your message will be added to the discussion below:
> 
> http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html 
> 
> To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
> <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 
> 
> 
> 
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: Temporary ID hasn't been replaced on commit

Posted by Michael Gentry <mg...@masslight.net>.
Hi Cristiano,

For Cayenne 3.0, it is in DataObjectUtils.intPKForObject().

mrg


On Fri, Mar 9, 2012 at 11:33 AM, cghersi <cr...@abodata.com> wrote:
> I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use?

RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Andrus, 

I cannot find documentation for your proposal (Cayenne.inPkForObject): may you give me an example of use?

 

Thank you very much.

Best

cghersi

 

From: Andrus Adamchik [via Cayenne] [mailto:ml-node+s195n3812833h55@n3.nabble.com] 
Sent: venerdì 9 marzo 2012 15:40
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 

> Is there any effective way to directly retrieve the ID of the just added 
> object after the context.commitChanges() invocation? 

After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too. 

Andrus 

On Mar 9, 2012, at 9:10 AM, cghersi wrote: 


> Hi all, perhaps I’ve understood something about the issue: 
> 
> Seems that the problem arises when I add a new object to the DB: just after 
> the insert, I need the autogenerated PK, and this seems to put in troubles 
> the method DataObjectUtils.intPKForObject(Persistent); 
> 
> Which sometimes throws the Exception in the subject. 
> 
> 
> 
> Is there any effective way to directly retrieve the ID of the just added 
> object after the context.commitChanges() invocation? 
> 
> 
> 
> Thank you very much for your help. 
> 
> 
> 
> Best 
> 
> cghersi 
> 
> 
> 
> From: cghersi [via Cayenne] [mailto:[hidden email]] 
> Sent: mercoledì 7 marzo 2012 09:43 
> To: cghersi 
> Subject: Re: Temporary ID hasn't been replaced on commit 
> 
> 
> 
> Hi Andrus, 
> 
> here there's the code that I use to save my object: 
> 
>        private AtomicReference<DataContext> context = new 
> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont 
> ext()); 
> 
>        public Network GetNetworkByPK(Integer pkID) { 
>                ObjectId id = new ObjectId(Network.class.getSimpleName(), 
> Network.ID_PK_COLUMN, pkID); 
> 
>                // this constructor implicitly uses "CACHE_REFRESH" policy, 
> so a fresh object will be returned 
>                ObjectIdQuery query = new ObjectIdQuery(id); 
>                return 
> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>        } 
> 
>        public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>                Expression qualifier = 
> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>                List<PhysicalNode> list = query(qualifier, 
> PhysicalNode.class); 
> 
>                //there can be only a single result from this query: 
>                return list.get(0); 
>        } 
> 
>        public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, 
> byte[] nsap, int netId, short type, 
>                        boolean isOnline, String defaultLabel){ 
> 
>                PhysicalNode pn=null; 
>                Network n = GetNetworkByPK(netId); 
>                if(n!=null){ 
>                        pn = GetPhysicalNodeByMac(macAddr); 
>                        if(pn==null){ 
>                                pn = createNewObj(PhysicalNode.class); 
>                                pn.setMacAddress(macAddr); 
>                                pn.setLabel(defaultLabel); 
>                                pn.setCoordX((double)-1); 
>                                pn.setCoordY((double)-1); 
>                                pn.setCoordZ((double)-1); 
>                                pn.setCreation((new Date()).getTime()); 
>                        } 
>                        pn.setNetwork(n); 
>                        pn.setNsap(nsap); 
>                        pn.setType(type); 
>                        pn.setIsOnline(isOnline); 
>                        CommitObjects(PhysicalNode.class); 
>                } 
>                else{ 
>                        throw new ValidationException("Network not in DB"); 
>                } 
>                return pn; 
>        } 
> 
> The problem is not systematic, but may occur with randomness if I force the 
> DB to add a great number of PhysicalNode objects in a little time window. 
> 
> Please, let me know if you have any idea! 
> 
> Thank you very much 
> Best 
> cghersi 
> 
>  _____   





  _____  

If you reply to this email, your message will be added to the discussion below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812833.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzfDUzMzUzMjY3> .
 <http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3813158.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
> Is there any effective way to directly retrieve the ID of the just added
> object after the context.commitChanges() invocation?

After commit the ID should be available via normal Cayenne APIs (e.g. Cayenne.inPkForObject). So there's something else at play too.

Andrus

On Mar 9, 2012, at 9:10 AM, cghersi wrote:
> Hi all, perhaps I’ve understood something about the issue:
> 
> Seems that the problem arises when I add a new object to the DB: just after
> the insert, I need the autogenerated PK, and this seems to put in troubles
> the method DataObjectUtils.intPKForObject(Persistent);
> 
> Which sometimes throws the Exception in the subject.
> 
> 
> 
> Is there any effective way to directly retrieve the ID of the just added
> object after the context.commitChanges() invocation?
> 
> 
> 
> Thank you very much for your help.
> 
> 
> 
> Best
> 
> cghersi
> 
> 
> 
> From: cghersi [via Cayenne] [mailto:ml-node+s195n3806195h77@n3.nabble.com] 
> Sent: mercoledì 7 marzo 2012 09:43
> To: cghersi
> Subject: Re: Temporary ID hasn't been replaced on commit
> 
> 
> 
> Hi Andrus, 
> 
> here there's the code that I use to save my object: 
> 
>        private AtomicReference<DataContext> context = new
> AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont
> ext()); 
> 
>        public Network GetNetworkByPK(Integer pkID) { 
>                ObjectId id = new ObjectId(Network.class.getSimpleName(),
> Network.ID_PK_COLUMN, pkID); 
> 
>                // this constructor implicitly uses "CACHE_REFRESH" policy,
> so a fresh object will be returned 
>                ObjectIdQuery query = new ObjectIdQuery(id); 
>                return
> (Network)DataObjectUtils.objectForQuery(context.get(), query); 
>        } 
> 
>        public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
>                Expression qualifier =
> ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
>                List<PhysicalNode> list = query(qualifier,
> PhysicalNode.class); 
> 
>                //there can be only a single result from this query: 
>                return list.get(0); 
>        } 
> 
>        public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr,
> byte[] nsap, int netId, short type, 
>                        boolean isOnline, String defaultLabel){ 
> 
>                PhysicalNode pn=null; 
>                Network n = GetNetworkByPK(netId); 
>                if(n!=null){ 
>                        pn = GetPhysicalNodeByMac(macAddr); 
>                        if(pn==null){ 
>                                pn = createNewObj(PhysicalNode.class); 
>                                pn.setMacAddress(macAddr); 
>                                pn.setLabel(defaultLabel); 
>                                pn.setCoordX((double)-1); 
>                                pn.setCoordY((double)-1); 
>                                pn.setCoordZ((double)-1); 
>                                pn.setCreation((new Date()).getTime()); 
>                        } 
>                        pn.setNetwork(n); 
>                        pn.setNsap(nsap); 
>                        pn.setType(type); 
>                        pn.setIsOnline(isOnline); 
>                        CommitObjects(PhysicalNode.class); 
>                } 
>                else{ 
>                        throw new ValidationException("Network not in DB"); 
>                } 
>                return pn; 
>        } 
> 
> The problem is not systematic, but may occur with randomness if I force the
> DB to add a great number of PhysicalNode objects in a little time window. 
> 
> Please, let me know if you have any idea! 
> 
> Thank you very much 
> Best 
> cghersi 
> 
>  _____  


RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi all, perhaps I’ve understood something about the issue:

Seems that the problem arises when I add a new object to the DB: just after
the insert, I need the autogenerated PK, and this seems to put in troubles
the method DataObjectUtils.intPKForObject(Persistent);

Which sometimes throws the Exception in the subject.

 

Is there any effective way to directly retrieve the ID of the just added
object after the context.commitChanges() invocation?

 

Thank you very much for your help.

 

Best

cghersi

 

From: cghersi [via Cayenne] [mailto:ml-node+s195n3806195h77@n3.nabble.com] 
Sent: mercoledì 7 marzo 2012 09:43
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 

Hi Andrus, 

here there's the code that I use to save my object: 

        private AtomicReference<DataContext> context = new
AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataCont
ext()); 
        
        public Network GetNetworkByPK(Integer pkID) { 
                ObjectId id = new ObjectId(Network.class.getSimpleName(),
Network.ID_PK_COLUMN, pkID); 

                // this constructor implicitly uses "CACHE_REFRESH" policy,
so a fresh object will be returned 
                ObjectIdQuery query = new ObjectIdQuery(id); 
                return
(Network)DataObjectUtils.objectForQuery(context.get(), query); 
        } 
        
        public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){ 
                Expression qualifier =
ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr); 
                List<PhysicalNode> list = query(qualifier,
PhysicalNode.class); 
                
                //there can be only a single result from this query: 
                return list.get(0); 
        } 
        
        public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr,
byte[] nsap, int netId, short type, 
                        boolean isOnline, String defaultLabel){ 

                PhysicalNode pn=null; 
                Network n = GetNetworkByPK(netId); 
                if(n!=null){ 
                        pn = GetPhysicalNodeByMac(macAddr); 
                        if(pn==null){ 
                                pn = createNewObj(PhysicalNode.class); 
                                pn.setMacAddress(macAddr); 
                                pn.setLabel(defaultLabel); 
                                pn.setCoordX((double)-1); 
                                pn.setCoordY((double)-1); 
                                pn.setCoordZ((double)-1); 
                                pn.setCreation((new Date()).getTime()); 
                        } 
                        pn.setNetwork(n); 
                        pn.setNsap(nsap); 
                        pn.setType(type); 
                        pn.setIsOnline(isOnline); 
                        CommitObjects(PhysicalNode.class); 
                } 
                else{ 
                        throw new ValidationException("Network not in DB"); 
                } 
                return pn; 
        } 

The problem is not systematic, but may occur with randomness if I force the
DB to add a great number of PhysicalNode objects in a little time window. 

Please, let me know if you have any idea! 

Thank you very much 
Best 
cghersi 

  _____  

If you reply to this email, your message will be added to the discussion
below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit
-tp3801043p3806195.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here
<http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe
_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzf
DUzMzUzMjY3> .
 
<http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewe
r&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNam
espace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.Nod
eNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emai
ls%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3812749.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Andrus,

here there's the code that I use to save my object:

	private AtomicReference<DataContext> context = new
AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataContext()); 
	
	public Network GetNetworkByPK(Integer pkID) {
		ObjectId id = new ObjectId(Network.class.getSimpleName(),
Network.ID_PK_COLUMN, pkID);

		// this constructor implicitly uses "CACHE_REFRESH" policy, so a fresh
object will be returned
		ObjectIdQuery query = new ObjectIdQuery(id);
		return (Network)DataObjectUtils.objectForQuery(context.get(), query);
	}
	
	public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){
		Expression qualifier =
ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr);
		List<PhysicalNode> list = query(qualifier, PhysicalNode.class); 
		
		//there can be only a single result from this query:
		return list.get(0);
	}
	
	public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, byte[]
nsap, int netId, short type, 
			boolean isOnline, String defaultLabel){

		PhysicalNode pn=null;
		Network n = GetNetworkByPK(netId);
		if(n!=null){
			pn = GetPhysicalNodeByMac(macAddr);
			if(pn==null){
				pn = createNewObj(PhysicalNode.class);
				pn.setMacAddress(macAddr);
				pn.setLabel(defaultLabel);	
				pn.setCoordX((double)-1);
				pn.setCoordY((double)-1);
				pn.setCoordZ((double)-1);
				pn.setCreation((new Date()).getTime());
			}
			pn.setNetwork(n);
			pn.setNsap(nsap);
			pn.setType(type);
			pn.setIsOnline(isOnline);
			CommitObjects(PhysicalNode.class);
		}
		else{
			throw new ValidationException("Network not in DB");
		}
		return pn;
	}

The problem is not systematic, but may occur with randomness if I force the
DB to add a great number of PhysicalNode objects in a little time window.

Please, let me know if you have any idea!

Thank you very much
Best
cghersi

--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3806195.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
I feel like at this point I can't help much without access to the code in debugger :-/

On Mar 6, 2012, at 4:48 AM, cghersi wrote:

> Hi Michael,
> thank you for the hint.
> I double checked the To Dep PK option and in fact some of the relationships
> were wrong, but nevertheless the problem persists.
> 
> The problem is now a NullPointerException on DataObjectUtils, line 114:
>       ObjectId id = dataObject.getObjectId();
>       if (!id.isTemporary()) {
>           return id.getIdSnapshot();
>       }
> id is null...
> 
> Any idea about this?
> 
> Thank you very much!
> Best
> cghersi
> 
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3803141.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
> 


Re: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Michael,
thank you for the hint.
I double checked the To Dep PK option and in fact some of the relationships
were wrong, but nevertheless the problem persists.

The problem is now a NullPointerException on DataObjectUtils, line 114:
        ObjectId id = dataObject.getObjectId();
        if (!id.isTemporary()) {
            return id.getIdSnapshot();
        }
id is null...

Any idea about this?

Thank you very much!
Best
cghersi

--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3803141.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Michael Gentry <mg...@masslight.net>.
That would be my guess ...

Can you double check that you do not have a cyclic graph?

The AshwoodEntitySorter sometimes gets wrapped around the axle and
doesn't throw an exception when it should.  When you have to-many (or
to-dependent PK) relationships, the owning object must be inserted
first.

A (id) ->> B (id, a_fk)

In this scenario, A must be inserted first to get the PK to push into
the FK in B.  Pretty easy to see/undersand in this case.  However, if
you have:

A ->> B ->> C ->> D ->> A

There is no correct way to insert that graph with auto-generated keys.

mrg


On Mon, Mar 5, 2012 at 11:41 AM, cghersi <cr...@abodata.com> wrote:
> This table is involved in a lot of relationships: is this a possible cause
> of failures?

Re: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Here there is the snippet of code that I use to save my object:
        ...
        private AtomicReference<DataContext> context = new
AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataContext());
	private <E> void CommitObjects(Class<E> objClass){
		synchronized(context){
			try{
				context.get().commitChanges();
			} catch(ValidationException e){
				log.warn("Validation failed. " + objClass.getName() +" discarded\n");
				e.printStackTrace();
				try{
					context.get().rollbackChanges();
				} catch(Exception e1){
					e1.printStackTrace();
				}
			} catch(Exception e){
				e.printStackTrace();
				try{
					context.get().rollbackChanges();
				} catch(Exception e1){
					e1.printStackTrace();
				}
				
			}
			log.debug("Registered Count:
"+context.get().getObjectStore().registeredObjectsCount());
			log.debug("New Count: "+ context.get().newObjects().size());
			log.debug("Delete Count: "+ context.get().deletedObjects().size());
			log.debug("Modify Count: "+ context.get().modifiedObjects().size());
			log.debug("Cache Size: "+context.get().getQueryCache().size());
			context.get().getObjectStore().getDataRowCache().clear();
			context.get().getQueryCache().clear();
		}
	}


Moreover, as you can see, I tried to add a synchronization on context in the
method that commit objects: the result has been a NullPointerException in
DataObjectUtils.java, line 114:
ObjectId id = dataObject.getObjectId();
        if (!id.isTemporary()) {
            return id.getIdSnapshot();
        }
on "id" object.

Is there any other clues that may I provide?

Thank you very much
Best
cghersi


--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801212.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

RE: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Andrus.

 

No, no relationships pointing to PhysicalNode have “To Dep PK” checked.

By the way, PhysicalNode table has 8 relationships, 4 of them have “To Dep
PK” checked and 4 of them haven’t.

 

cghersi

 

From: Andrus Adamchik [via Cayenne]
[mailto:ml-node+s195n3801210h42@n3.nabble.com] 
Sent: lunedì 5 marzo 2012 17:49
To: cghersi
Subject: Re: Temporary ID hasn't been replaced on commit

 


On Mar 5, 2012, at 11:41 AM, cghersi wrote: 

> This table is involved in a lot of relationships: is this a possible cause

> of failures? 

Possibly. Can you check if there is a relationship pointing to this table
with "To Dep PK" checked. 

Andrus 




  _____  

If you reply to this email, your message will be added to the discussion
below:

http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit
-tp3801043p3801210.html 

To unsubscribe from Temporary ID hasn't been replaced on commit, click here
<http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe
_by_code&node=3801043&code=Y3Jpc3RpYW5vLmdoZXJzaUBhYm9kYXRhLmNvbXwzODAxMDQzf
DUzMzUzMjY3> .
 
<http://cayenne.195.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewe
r&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNam
espace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.Nod
eNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emai
ls%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801223.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Mar 5, 2012, at 11:41 AM, cghersi wrote:

> This table is involved in a lot of relationships: is this a possible cause
> of failures?

Possibly. Can you check if there is a relationship pointing to this table with "To Dep PK" checked.

Andrus


Re: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
here there is the part of xml config file:
	<db-entity name="PhysicalNode" catalog="PacketDb">
		<db-attribute name="AdditionalArgs" type="VARCHAR" length="4000"/>
		<db-attribute name="BatteryLevel" type="SMALLINT"/>
		<db-attribute name="CoordX" type="DOUBLE" isMandatory="true"/>
		<db-attribute name="CoordY" type="DOUBLE" isMandatory="true"/>
		<db-attribute name="CoordZ" type="DOUBLE" isMandatory="true"/>
		<db-attribute name="Creation" type="BIGINT" isMandatory="true"/>
		<db-attribute name="CurrentPwrSrc" type="SMALLINT"/>
		<db-attribute name="ExpectedLifeTime" type="BIGINT"/>
		<db-attribute name="Id" type="INTEGER" isPrimaryKey="true"
isGenerated="true" isMandatory="true" length="10"/>
		<db-attribute name="IsOnline" type="BOOLEAN" isMandatory="true"/>
		<db-attribute name="Label" type="VARCHAR" isMandatory="true"
length="255"/>
		<db-attribute name="LastBatteryChange" type="BIGINT"/>
		<db-attribute name="LastMaintenance" type="BIGINT"/>
		<db-attribute name="LastStatusTime" type="BIGINT"/>
		<db-attribute name="MacAddress" type="BLOB" isMandatory="true"
length="24"/>
		<db-attribute name="NSAP" type="BLOB" isMandatory="true" length="16"/>
		<db-attribute name="NetworkId" type="INTEGER" isMandatory="true"/>
		<db-attribute name="SignalRange" type="FLOAT"/>
		<db-attribute name="Type" type="SMALLINT" isMandatory="true"/>
		<db-attribute name="WakeupPolicy" type="SMALLINT"/>
	</db-entity>


	<obj-entity name="PhysicalNode" className="dbManager.PhysicalNode"
dbEntityName="PhysicalNode">
		<obj-attribute name="additionalArgs" type="java.lang.String"
db-attribute-path="AdditionalArgs"/>
		<obj-attribute name="batteryLevel" type="java.lang.Short"
db-attribute-path="BatteryLevel"/>
		<obj-attribute name="coordX" type="double" db-attribute-path="CoordX"/>
		<obj-attribute name="coordY" type="double" db-attribute-path="CoordY"/>
		<obj-attribute name="coordZ" type="double" db-attribute-path="CoordZ"/>
		<obj-attribute name="creation" type="long" db-attribute-path="Creation"/>
		<obj-attribute name="currentPwrSrc" type="java.lang.Short"
db-attribute-path="CurrentPwrSrc"/>
		<obj-attribute name="expectedLifeTime" type="java.lang.Long"
db-attribute-path="ExpectedLifeTime"/>
		<obj-attribute name="isOnline" type="boolean"
db-attribute-path="IsOnline"/>
		<obj-attribute name="label" type="java.lang.String"
db-attribute-path="Label"/>
		<obj-attribute name="lastBatteryChange" type="java.lang.Long"
db-attribute-path="LastBatteryChange"/>
		<obj-attribute name="lastMaintenance" type="java.lang.Long"
db-attribute-path="LastMaintenance"/>
		<obj-attribute name="lastStatusTime" type="java.lang.Long"
db-attribute-path="LastStatusTime"/>
		<obj-attribute name="macAddress" type="byte[]"
db-attribute-path="MacAddress"/>
		<obj-attribute name="nsap" type="byte[]" db-attribute-path="NSAP"/>
		<obj-attribute name="signalRange" type="java.lang.Float"
db-attribute-path="SignalRange"/>
		<obj-attribute name="type" type="short" db-attribute-path="Type"/>
		<obj-attribute name="wakeupPolicy" type="java.lang.Short"
db-attribute-path="WakeupPolicy"/>
	</obj-entity>

This table is involved in a lot of relationships: is this a possible cause
of failures?

Any other idea?

Let me know!

Thank you very much
Best 
cghersi



--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801195.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
Looks good. If it is also "Database-generated" in Cayenne model, then everything I can think of is correct.

Based on the information that you've provided, I can't think of anything else Cayenne-related that might cause it :-/

Andrus

On Mar 5, 2012, at 11:10 AM, cghersi wrote:
> Hi Andrus, thank you for the fast reply!
> 
> The DB is MySQL.
> The table is created with a code like this:
> CREATE TABLE PhysicalNode (AdditionalArgs VARCHAR(4000) NULL, BatteryLevel
> SMALLINT NULL, CoordX DOUBLE NOT NULL, CoordY DOUBLE NOT NULL, CoordZ DOUBLE
> NOT NULL, Creation BIGINT NOT NULL, CurrentPwrSrc SMALLINT NULL,
> ExpectedLifeTime BIGINT NULL, Id INT NOT NULL AUTO_INCREMENT, IsOnline BOOL
> NOT NULL, Label VARCHAR(255) NOT NULL, LastBatteryChange BIGINT NULL,
> LastMaintenance BIGINT NULL, LastStatusTime BIGINT NULL, MacAddress LONGBLOB
> NOT NULL, NSAP LONGBLOB NOT NULL, NetworkId INT NOT NULL, SignalRange FLOAT
> NULL, Type SMALLINT NOT NULL, WakeupPolicy SMALLINT NULL, PRIMARY KEY (Id))
> ENGINE=InnoDB
> ;
> 
> You can see the PK is "Id" and it is AUTO_INCREMENT.
> 
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801088.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
> 


Re: Temporary ID hasn't been replaced on commit

Posted by cghersi <cr...@abodata.com>.
Hi Andrus, thank you for the fast reply!

The DB is MySQL.
The table is created with a code like this:
CREATE TABLE PhysicalNode (AdditionalArgs VARCHAR(4000) NULL, BatteryLevel
SMALLINT NULL, CoordX DOUBLE NOT NULL, CoordY DOUBLE NOT NULL, CoordZ DOUBLE
NOT NULL, Creation BIGINT NOT NULL, CurrentPwrSrc SMALLINT NULL,
ExpectedLifeTime BIGINT NULL, Id INT NOT NULL AUTO_INCREMENT, IsOnline BOOL
NOT NULL, Label VARCHAR(255) NOT NULL, LastBatteryChange BIGINT NULL,
LastMaintenance BIGINT NULL, LastStatusTime BIGINT NULL, MacAddress LONGBLOB
NOT NULL, NSAP LONGBLOB NOT NULL, NetworkId INT NOT NULL, SignalRange FLOAT
NULL, Type SMALLINT NOT NULL, WakeupPolicy SMALLINT NULL, PRIMARY KEY (Id))
ENGINE=InnoDB
;

You can see the PK is "Id" and it is AUTO_INCREMENT.

--
View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801088.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: Temporary ID hasn't been replaced on commit

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi cghersi,

can you check the table in question on the DB side to see that it is configured to autoincrement an ID column. You haven't mentioned what DB you are using, so here is an example for MySQL (see 'auto_increment' in the 'Extra' column) :

> desc mytable;
+--------------------------------+--------------+------+-----+---------+----------------+
| Field                          | Type         | Null | Key | Default | Extra          |
+--------------------------------+--------------+------+-----+---------+----------------+
| ID                             | int(11)      | NO   | PRI | NULL    | auto_increment | 
| EMAIL                          | varchar(128) | NO   | UNI | NULL    |                | 

Cheers,
Andrus

On Mar 5, 2012, at 10:57 AM, cghersi wrote:

> Hi all,
> 
> I'm using Cayenne 3.0. For more then 1 year we hadn't got any issue; now,
> suddenly, sometimes it appears a strange Exception: "Temporary ID hasn't
> been replaced on commit".
> It appears on an object whose table has an autogenerated PK.
> 
> What can I do to avoid such a situation?
> 
> Thank you very much.
> Best
> cghersi
> 
> 
> --
> View this message in context: http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3801043.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>