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 |
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. _______________________________________________ SmallWiki, Magritte, Pier and Related Tools ... https://www.iam.unibe.ch/mailman/listinfo/smallwiki |
Free forum by Nabble | Edit this page |