[vw7.3][Glorp]New object into database

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

[vw7.3][Glorp]New object into database

Milan Čermák
Hi all, (Alan namely)
I tried to use Glorp for one project of mine. Unfortunately I stuck on a
basic approach of inserting new object (row) into the database.
All documentation I looked into says that GlorpSession>>register: should
do the trick. But as I browse that method, it takes some kind of proxy
as an argument taking no action for "real" objects.
Even if I tried to use that method, Glorp tries to do an UPDATE on SQL
database when I performed #commitUnitOfWork. No INSERT took place.

I wonder how to acomplish this simple thing. Thanks for hints.
--
Ing. Milan Čermák
programátor, analytik

[hidden email]

................................................................
e-FRACTAL, s.r.o. => e-business driven company
nám. Míru 15, Praha 2, http://www.e-fractal.cz
tel: 222 512 000, fax: 222 515 000
................................................................


Reply | Threaded
Open this post in threaded view
|

Re: [vw7.3][Glorp]New object into database

Alan Knight-2
register: is what you want, either to tell the system about a new object, or to tell it that an old object is of interest in the current transaction. I think the code you're getting confused by in that method is code that tries to get at the real object if it is held inside a proxy.

If it's trying to do an update rather than an insert, that means it's confused about whether the object is new or not. That's determined by whether the object is already in the cache, which it does by looking it up by the primary key (if the object doesn't have a primary key, then we can assume it's not in the database). So if it's getting confused about that, the most likely reason is confusion over the primary key. So, does the table in question have its primary key defined in the glorp table definition method. And if so, could the new object have the same primary key as one that's already in the cache. Checking what happens in the Session>>isNew: method when called for your object might be helpful.

At 10:44 AM 1/19/2006, =?ISO-8859-2?Q?Milan_=C8erm=E1k?= wrote:

>Hi all, (Alan namely)
>I tried to use Glorp for one project of mine. Unfortunately I stuck on a basic approach of inserting new object (row) into the database.
>All documentation I looked into says that GlorpSession>>register: should do the trick. But as I browse that method, it takes some kind of proxy as an argument taking no action for "real" objects.
>Even if I tried to use that method, Glorp tries to do an UPDATE on SQL database when I performed #commitUnitOfWork. No INSERT took place.
>
>I wonder how to acomplish this simple thing. Thanks for hints.
>--
>Ing. Milan Èermák
>programátor, analytik
>
>[hidden email]
>
>................................................................
>e-FRACTAL, s.r.o. => e-business driven company
>nám. Míru 15, Praha 2, http://www.e-fractal.cz
>tel: 222 512 000, fax: 222 515 000
>................................................................
>

--
Alan Knight [|], Cincom Smalltalk Development
[hidden email]
[hidden email]
http://www.cincom.com/smalltalk

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