cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cghersi <cristiano.ghe...@abodata.com>
Subject RE: Temporary ID hasn't been replaced on commit
Date Mon, 12 Mar 2012 09:01:10 GMT
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.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message