Duplicate key question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Duplicate key question

Brian M
I'm using Ramon Leon's MagritteGlorp package, which ties together the  
extremely useful Magritte and Glorp packages, but must not be using  
it quite correctly. When registering an object that has a reference  
to an already stored object, it seems to attempt re-insert the  
referenced object. For example:

objA := ADescriptorSystem getSession execute: (A find where [:ea | ea  
name = 'hello']).
objB := B new.
objB a: objA.
session := B getSession.
session beginUnitOfWork.
objB register: objB.
session commitUnitOfWork.

raises a 'GlorpDatabaseWriteError: ERROR: duplicate key violates  
unique constraint' error. I thought it might be because I am using  
one session to load the object and another session to register, but  
believe I've also tried doing everything in one session. If it is of  
any help, the reference description is of type  
MAToOneRelationDescription. On another project, I tried  
MAMultipleOptionDescription with the same error. Any ideas on how to  
make it recognize the object is already stored and hasn't changed?

Thanks, Brian.

Glorp.rjl.8
GlorpPostload-rjl.3
GlorpPreload-rjl.2
Magritte-Seaside-lr.228.mcz
Magritte-Model-lr.266
MagritteGlorp-rjl.47


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: [Glorp-development] Duplicate key question

Brian M
Thanks for the responses. I did get this to work by using one session for reading the nested object and registering the new object. One of the situations where another session's objects would be nice to use is that rarely changed nested objects could be cached in memory rather than running another query. Glorp is efficient enough that I should worry about such things, but old habits die hard :)

Brian.


On May 30, 2007, at 6:31 AM, Alan Knight wrote:

I don't quite know why this would be happening, partly because I don't know the MagritteGlorp package, so I'm not sure what some of these calls are doing. My guess is that it is because you're using two different sessions. In general, it's a very bad idea to mix objects between two different sessions. Glorp relies on knowing whether or not it read the object from the database in order to know whether to do an insert or an update. If you read objA in one session, then give it to another session as if it were a new object, it will probably try to insert it and cause an error. If you did this in the same session, I'd expect it to work. Certainly that sort of thing works fine in basic Glorp.

At 01:02 AM 5/30/2007, Brian Murphy-Dye wrote:
I'm using Ramon Leon's MagritteGlorp package, which ties together the 
extremely useful Magritte and Glorp packages, but must not be using 
it quite correctly. When registering an object that has a reference 
to an already stored object, it seems to attempt re-insert the 
referenced object. For example:

objA := ADescriptorSystem getSession execute: (A find where [:ea | ea 
name = 'hello']).
objB := B new.
objB a: objA.
session := B getSession.
session beginUnitOfWork.
objB register: objB.
session commitUnitOfWork.

raises a 'GlorpDatabaseWriteError: ERROR: duplicate key violates 
unique constraint' error. I thought it might be because I am using 
one session to load the object and another session to register, but 
believe I've also tried doing everything in one session. If it is of 
any help, the reference description is of type 
MAToOneRelationDescription. On another project, I tried 
MAMultipleOptionDescription with the same error. Any ideas on how to 
make it recognize the object is already stored and hasn't changed?

Thanks, Brian.

Glorp.rjl.8
GlorpPostload-rjl.3
GlorpPreload-rjl.2
Magritte-Seaside-lr.228.mcz
Magritte-Model-lr.266
MagritteGlorp-rjl.47


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Glorp-development mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/glorp-development

--
Alan Knight [|], Cincom Smalltalk Development

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." - Niall Ross



_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki