You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Francois Eyl <fe...@smaeur.com> on 2008/08/01 12:12:52 UTC

Update in cascade

Hello all,

Is there a way with Cayenne to do an update in cascade with 
relationships (something like the delete in cascade already implemented) ?

Thanks.

Francois

___________________________________________________

Ce message a été vérifié par l'antivirus de MDaemon 5 .

Par précaution, n'ouvrez pas de pièces jointes de correspondants inconnus.
___________________________________________________


Re: Update in cascade

Posted by Andrus Adamchik <an...@objectstyle.org>.
I guess the "Cayenne way" in this situation would be to clone an  
object subtree with a new PK and delete the old subtree. I.e. INSERT/ 
DELETE vs UPDATE. Fro the reasons that Ari stated - it is assumed that  
object identity is never changed.

Andrus


On Aug 1, 2008, at 9:47 AM, Francois Eyl wrote:

> First, you have to know that I have no control on the database  
> architecture because this is a customer's database (poor and old  
> existing database).
>
> So, in this database, unfortunately, Name field is PK, and I have no  
> choice, I need to do a rename even if it is a PK.
>
> Thanks.
>
> Francois
>
> Aristedes Maniatis wrote:
>>
>> On 01/08/2008, at 10:05 PM, Francois Eyl wrote:
>>
>>> What I need is, to change the Name (PK) value of my object, and  
>>> here I need to change the Name in every related object. But I need  
>>> to do this on the same SQL transaction.
>>
>> The question you'll probably get back from many people is: why are  
>> you trying to change the PK of the object? That is supposed to be  
>> the one immutable property of the object. If you are changing the  
>> PK of existing objects in your database, you may need to rethink  
>> your strategy. On the whole, avoid using meaningful data as the  
>> primary key and your job will be much simpler. Cayenne gives you a  
>> range of options to automatically create nearly sequential primary  
>> keys.
>>
>> Ari Maniatis
>>
>>
>>
>> -------------------------->
>> ish
>> http://www.ish.com.au
>> Level 1, 30 Wilson Street Newtown 2042 Australia
>> phone +61 2 9550 5001 fax +61 2 9550 4001
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
>>
>>
>>
>>
>>
>
> ___________________________________________________
>
> Ce message a ete verifie par l'antivirus de MDaemon 5 .
>
> Par precaution, n'ouvrez pas de pieces jointes de correspondants  
> inconnus.
> ___________________________________________________
>
>


Re: Update in cascade

Posted by Francois Eyl <fe...@smaeur.com>.
First, you have to know that I have no control on the database 
architecture because this is a customer's database (poor and old 
existing database).

So, in this database, unfortunately, Name field is PK, and I have no 
choice, I need to do a rename even if it is a PK.

Thanks.

Francois

Aristedes Maniatis wrote:
>
> On 01/08/2008, at 10:05 PM, Francois Eyl wrote:
>
>> What I need is, to change the Name (PK) value of my object, and here 
>> I need to change the Name in every related object. But I need to do 
>> this on the same SQL transaction.
>
> The question you'll probably get back from many people is: why are you 
> trying to change the PK of the object? That is supposed to be the one 
> immutable property of the object. If you are changing the PK of 
> existing objects in your database, you may need to rethink your 
> strategy. On the whole, avoid using meaningful data as the primary key 
> and your job will be much simpler. Cayenne gives you a range of 
> options to automatically create nearly sequential primary keys.
>
> Ari Maniatis
>
>
>
> -------------------------->
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001 fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
>
>
>
>
>

___________________________________________________

Ce message a ete verifie par l'antivirus de MDaemon 5 .

Par precaution, n'ouvrez pas de pieces jointes de correspondants inconnus.
___________________________________________________


Re: Update in cascade

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 01/08/2008, at 10:05 PM, Francois Eyl wrote:

> What I need is, to change the Name (PK) value of my object, and here  
> I need to change the Name in every related object. But I need to do  
> this on the same SQL transaction.

The question you'll probably get back from many people is: why are you  
trying to change the PK of the object? That is supposed to be the one  
immutable property of the object. If you are changing the PK of  
existing objects in your database, you may need to rethink your  
strategy. On the whole, avoid using meaningful data as the primary key  
and your job will be much simpler. Cayenne gives you a range of  
options to automatically create nearly sequential primary keys.

Ari Maniatis



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: Update in cascade

Posted by Francois Eyl <fe...@smaeur.com>.
Not sure that callbacks is enough.

What I need is, to change the Name (PK) value of my object, and here I 
need to change the Name in every related object. But I need to do this 
on the same SQL transaction.

Thanks.

Francois

Aristedes Maniatis wrote:
>
> On 01/08/2008, at 8:12 PM, Francois Eyl wrote:
>
>> Is there a way with Cayenne to do an update in cascade with 
>> relationships (something like the delete in cascade already 
>> implemented) ?
>
> Not 100% sure what you are wanting to achieve, but will lifecycle 
> callbacks do what you need?
>
> http://cayenne.apache.org/doc/lifecycle-callbacks.html
>
>
> Ari Maniatis
>
>
>
> -------------------------->
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001 fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
>
>
>
>
>

___________________________________________________

Ce message a ete verifie par l'antivirus de MDaemon 5 .

Par precaution, n'ouvrez pas de pieces jointes de correspondants inconnus.
___________________________________________________


Re: Update in cascade

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 01/08/2008, at 8:12 PM, Francois Eyl wrote:

> Is there a way with Cayenne to do an update in cascade with  
> relationships (something like the delete in cascade already  
> implemented) ?

Not 100% sure what you are wanting to achieve, but will lifecycle  
callbacks do what you need?

http://cayenne.apache.org/doc/lifecycle-callbacks.html


Ari Maniatis



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A