You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Abid Hussain <ab...@abid76.de> on 2006/05/12 17:14:29 UTC
updating the primary key of a table row
Hi everybody,
i wonder how to perform an update on a table where i changed the primary
key.
Let's say i've got a table, where the only unique column is the primary
key itself - like this:
CREATE TABLE foo (
foo_name VARCHAR PRIMARY KEY
);
Now I change the column foo_name of a row from 'bla' to 'blub' and
perform an update.
In SQL, I would do this:
UPDATE foo SET foo_name = 'blub' WHERE foo_name = 'bla';
When using OJB I would first retrieve the object I want to update:
Foo foo = new Foo();
foo.setFooName("bla");
Query q = new QueryByIdentity(foo);
foo = (Foo) broker.getObjectByQuery(q);
Then set the attribute fooName:
foo.setFooName("blub");)
Then perform update:
broker.store(foo, ObjectModification.UPDATE);
But how should OJB identify the object which is to be updated? I just
have changed the primary key and there are not other unique columns!
Any ideas?
Regards,
Abid Hussain
--
Abid Hussain
Mail: abid.hussain@abid76.de
Web: http://www.abid76.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: updating the primary key of a table row
Posted by Abid Hussain <ab...@abid76.de>.
Hi Armin,
> For this special case you have to delete the old value/obj and then
> insert the new vale/obj.
>
> regards,
> Armin
thanks a lot. I thought of this possibility, but wondered if there is
another way to perform the update.
Regards,
Abid
--
Abid Hussain
Mail: abid.hussain@abid76.de
Web: http://www.abid76.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: updating the primary key of a table row
Posted by Armin Waibel <ar...@apache.org>.
Hi Abid,
Abid Hussain wrote:
> Hi everybody,
>
> i wonder how to perform an update on a table where i changed the primary
> key.
You can't change a PK value in OJB and at least OJB needs one PK field.
>
> Let's say i've got a table, where the only unique column is the primary
> key itself - like this:
> CREATE TABLE foo (
>
> foo_name VARCHAR PRIMARY KEY
> );
For this special case you have to delete the old value/obj and then
insert the new vale/obj.
regards,
Armin
>
> Now I change the column foo_name of a row from 'bla' to 'blub' and
> perform an update.
> In SQL, I would do this:
> UPDATE foo SET foo_name = 'blub' WHERE foo_name = 'bla';
>
> When using OJB I would first retrieve the object I want to update:
> Foo foo = new Foo();
> foo.setFooName("bla");
> Query q = new QueryByIdentity(foo);
> foo = (Foo) broker.getObjectByQuery(q);
>
> Then set the attribute fooName:
> foo.setFooName("blub");)
>
> Then perform update:
> broker.store(foo, ObjectModification.UPDATE);
>
> But how should OJB identify the object which is to be updated? I just
> have changed the primary key and there are not other unique columns!
>
> Any ideas?
>
> Regards,
>
> Abid Hussain
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org