You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by ha...@welinux.cl on 2009/03/20 00:07:22 UTC
Table with no sequence
Hi,
We have a legacy table that have a meaningful primary key, many code depends on it and it's not possible to alter it.
We are building new java applications that need to insert in it.
We would like to cayenne it and not use any sequence at all for making inserts...
¿ it's possible to do it ?
Regards
Hans
Re: Table with no sequence
Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 20/03/2009, at 10:07 AM, hans@welinux.cl wrote:
> Hi,
>
> We have a legacy table that have a meaningful primary key, many code
> depends on it and it's not possible to alter it.
> We are building new java applications that need to insert in it.
>
> We would like to cayenne it and not use any sequence at all for
> making inserts...
>
> ¿ it's possible to do it ?
Choose "database generated" as your PK generation strategy in the
modeler.
Ari
-------------------------->
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: Table with no sequence
Posted by Michael Gentry <mg...@masslight.net>.
Well, almost all of us have had legacy schemas that did such things
and we have to deal with them. Good luck!
mrg
On Fri, Mar 20, 2009 at 10:53 AM, <ha...@welinux.cl> wrote:
> Hi,
>
> Thank you for all the feedback, i can see that there is plenty of solutions that were not obvious at first. Yes I'm using 3.0.
>
> At first i thought i was committing a sin making this question, i smelled something religious against meaningful primary keys in legacy systems.
>
> Regards
> Hans
>
> ----- "Michael Gentry" <mg...@masslight.net> escribió:
>
>> If you assign your primary key(s) manually, before telling Cayenne to
>> commitChanges(), then you'll be fine. Cayenne will honor the PK
>> value
>> that you set without trying to replace it.
>>
>> You didn't mention which version of Cayenne, but for version 2.0 (and
>> I suppose even in 3.0) you can override your data object's
>> setPersistenceState() method:
>>
>> public void setPersistenceState(int state)
>> {
>> super.setPersistenceState(state);
>>
>> if (state == PersistenceState.NEW)
>> {
>> // Initialize PK here.
>> }
>> }
>>
>>
>> For Cayenne 3.0, you can use the new lifecycle callbacks:
>>
>> http://cayenne.apache.org/doc/lifecycle-callbacks.html
>>
>>
>> mrg
>>
>>
>> On Thu, Mar 19, 2009 at 7:07 PM, <ha...@welinux.cl> wrote:
>> > Hi,
>> >
>> > We have a legacy table that have a meaningful primary key, many code
>> depends on it and it's not possible to alter it.
>> > We are building new java applications that need to insert in it.
>> >
>> > We would like to cayenne it and not use any sequence at all for
>> making inserts...
>> >
>> > ¿ it's possible to do it ?
>> >
>> > Regards
>> > Hans
>> >
>
> --
> Hans Poo, WeLinux S.A.
> Oficina: 697.25.42, Celular: 09-319.93.05
> Bombero Ossa # 1010, Santiago
>
>
Re: Table with no sequence
Posted by ha...@welinux.cl.
Hi,
Thank you for all the feedback, i can see that there is plenty of solutions that were not obvious at first. Yes I'm using 3.0.
At first i thought i was committing a sin making this question, i smelled something religious against meaningful primary keys in legacy systems.
Regards
Hans
----- "Michael Gentry" <mg...@masslight.net> escribió:
> If you assign your primary key(s) manually, before telling Cayenne to
> commitChanges(), then you'll be fine. Cayenne will honor the PK
> value
> that you set without trying to replace it.
>
> You didn't mention which version of Cayenne, but for version 2.0 (and
> I suppose even in 3.0) you can override your data object's
> setPersistenceState() method:
>
> public void setPersistenceState(int state)
> {
> super.setPersistenceState(state);
>
> if (state == PersistenceState.NEW)
> {
> // Initialize PK here.
> }
> }
>
>
> For Cayenne 3.0, you can use the new lifecycle callbacks:
>
> http://cayenne.apache.org/doc/lifecycle-callbacks.html
>
>
> mrg
>
>
> On Thu, Mar 19, 2009 at 7:07 PM, <ha...@welinux.cl> wrote:
> > Hi,
> >
> > We have a legacy table that have a meaningful primary key, many code
> depends on it and it's not possible to alter it.
> > We are building new java applications that need to insert in it.
> >
> > We would like to cayenne it and not use any sequence at all for
> making inserts...
> >
> > ¿ it's possible to do it ?
> >
> > Regards
> > Hans
> >
--
Hans Poo, WeLinux S.A.
Oficina: 697.25.42, Celular: 09-319.93.05
Bombero Ossa # 1010, Santiago
Re: Table with no sequence
Posted by Michael Gentry <mg...@masslight.net>.
If you assign your primary key(s) manually, before telling Cayenne to
commitChanges(), then you'll be fine. Cayenne will honor the PK value
that you set without trying to replace it.
You didn't mention which version of Cayenne, but for version 2.0 (and
I suppose even in 3.0) you can override your data object's
setPersistenceState() method:
public void setPersistenceState(int state)
{
super.setPersistenceState(state);
if (state == PersistenceState.NEW)
{
// Initialize PK here.
}
}
For Cayenne 3.0, you can use the new lifecycle callbacks:
http://cayenne.apache.org/doc/lifecycle-callbacks.html
mrg
On Thu, Mar 19, 2009 at 7:07 PM, <ha...@welinux.cl> wrote:
> Hi,
>
> We have a legacy table that have a meaningful primary key, many code depends on it and it's not possible to alter it.
> We are building new java applications that need to insert in it.
>
> We would like to cayenne it and not use any sequence at all for making inserts...
>
> ¿ it's possible to do it ?
>
> Regards
> Hans
>
Re: Table with no sequence
Posted by Juergen Saar <ju...@jsaar.org>.
I also have such a project ... I think it's pretty easy doing such work with
cayenne.
We use the validateForInsert method for generating the PrimaryKey.
We started development with cayenne 1.x ... since Version 2 there are more
ways to solve this isssue
but you know "newer touch ..."
2009/3/20 <ha...@welinux.cl>
> Hi,
>
> We have a legacy table that have a meaningful primary key, many code
> depends on it and it's not possible to alter it.
> We are building new java applications that need to insert in it.
>
> We would like to cayenne it and not use any sequence at all for making
> inserts...
>
> ¿ it's possible to do it ?
>
> Regards
> Hans
>