You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Carlos Chavez <cc...@agssa.net> on 2006/02/17 21:30:11 UTC

updating PrimaryKey

Hello jakob, armin, list.

I have two tables:

table1 (id1, name1)  PrimaryKey is id1.
table2 (id2, id1, name2)  PrimaryKey is id2, ForeignKey is id1 
referencing to table1
There is a relationship one to many from table1 to table2
There is cascade uptade and delete.

when i update the value of the primary key for a record on table1 OJB 
don't update the value of the primary key instead of that create a new 
record.
On table2 OJB update the value of the foreingkey to the new value.

For example:

Table1
id1       name1
1         aaaaaaa

Table2
id2      id1    name2
1         1       bbbbbbb
2         1       cccccccc

when i update the primarykey on table1, for example to 4 the records are:

Table1
id1       name1
1         aaaaaaa
4         aaaaaaa

Table2
id2      id1    name2
1         4       bbbbbbb
2         4       cccccccc

on the table1 create a new record and on the table2 update the 
foreignkey to the new value.

I use db-ojb 1.0.4.

Cheers,
Carlos Chavez.


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: updating PrimaryKey

Posted by Armin Waibel <ar...@apache.org>.
Hi Carlos,

Carlos Chavez wrote:
> Hello jakob, armin, list.
> 
> I have two tables:
> 
> table1 (id1, name1)  PrimaryKey is id1.
> table2 (id2, id1, name2)  PrimaryKey is id2, ForeignKey is id1 
> referencing to table1
> There is a relationship one to many from table1 to table2
> There is cascade uptade and delete.
> 
> when i update the value of the primary key for a record on table1 OJB 
> don't update the value of the primary key instead of that create a new 
> record.
> On table2 OJB update the value of the foreingkey to the new value.
> 

It's not allowed to change a PK column, OJB expects that this value
never change. If you change it and the "new" PK doesn't exists, OJB 
"detects" a new object --> insert of new row.

regards,
Armin


> For example:
> 
> Table1
> id1       name1
> 1         aaaaaaa
> 
> Table2
> id2      id1    name2
> 1         1       bbbbbbb
> 2         1       cccccccc
> 
> when i update the primarykey on table1, for example to 4 the records are:
> 
> Table1
> id1       name1
> 1         aaaaaaa
> 4         aaaaaaa
> 
> Table2
> id2      id1    name2
> 1         4       bbbbbbb
> 2         4       cccccccc
> 
> on the table1 create a new record and on the table2 update the 
> foreignkey to the new value.
> 
> I use db-ojb 1.0.4.
> 
> Cheers,
> Carlos Chavez.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org