You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Juergen Saar <ju...@jsaar.org> on 2009/07/30 07:24:43 UTC

The right way to populate meaningful keys

Hi all,

I'm using cayenne within an old 4GL-Project with meaningful Primary Keys.

Is there a 'best practice' to get this keys into the DataObject-Instance?

Actually I've various trouble with this ...


Any hint or code-sniplet would be helpful ...
-Juergen-

Re: The right way to populate meaningful keys

Posted by Juergen Saar <ju...@jsaar.org>.
It is a very old Project (started 1987) and cayenne is running on top of it.

All newer Data-Organization is done with technical PK,
but to change this old Data-Organization too much changes
in the old 4GL-Software have to be done.

And you know: Never change a ...

2009/7/30 Eric Lazarus <er...@yahoo.com>

>
> (Reminder: Avoid meaningful keys when you have the choice, like anytime you
> are designing the database from scratch.
>
> Who wants to write the wikipedia article on the meaningful pointer
> problem...?)
>
> Eric
> +1 (917) 589-6579
>
>
> --- On Thu, 7/30/09, Michael Gentry <mg...@masslight.net> wrote:
>
> > From: Michael Gentry <mg...@masslight.net>
> > Subject: Re: The right way to populate meaningful keys
> > To: user@cayenne.apache.org
> > Date: Thursday, July 30, 2009, 11:01 AM
> > Hi Juergen,
> >
> > I suspect that you need to assign the key on the other side
> > of your
> > 1:1 relationship, too.  Another thing you could try
> > doing is using the
> > To Dep PK checkbox in the DbEntity Relationship panel to
> > see if
> > Cayenne will auto-copy your meaningful PK for you.
> >
> > http://cayenne.apache.org/doc/to-dep-pk-checkbox.html
> >
> > I'm not sure if the To Dep PK will work that way, but it is
> > worth a
> > try.  If you assign all the keys, though, it should
> > work.
> >
> >
> > On Thu, Jul 30, 2009 at 10:53 AM, Juergen Saar<ju...@jsaar.org>
> > wrote:
> > > This was my way  ...
> > > But I ran in deep trouble with the ObjectId ... this
> > seems not to be
> > > sycronized
> > >
> > > My actual CayenneRuntimeException:
> > > Can't extract a master key. Missing key (esd_abteil),
> > master ID
> > > (<ObjectId:EsSend, TEMP:0000021E6A770001>)
> > >
> > > It belongs to a 1:1 Relation and the PK-Values in
> > source and target are
> > > correctly set.
> > > The Commit is interrupted and the Relation-Data are
> > not inserted to DB.
> > >
> > >
> > > In nearly all cases ... even when all data is inserted
> > in DB the following
> > > CayenneRuntimException is thrown:
> > > Temporary ID hasn't been replaced on
> > commit:{<ObjectId:EsSend,
> > > TEMP:0000022273C50001>; new; ...}
> > >
> > > Any idea?
> > > -Juergen-
> > >
> > > PS: I'm using the Version 2.0.4
> > >
> > >
> > > 2009/7/30 Michael Gentry <mg...@masslight.net>
> > >
> > >> Cayenne, by default, doesn't map keys from the
> > DbEntity (database
> > >> definition) to the ObjEntity (Java definition),
> > but you can go into
> > >> the ObjEntity and add them and it should be fine.
> >  After you do that,
> > >> just call the set/get methods for the keys to
> > set/get them.  If you
> > >> set a key on a new object before you
> > commitChanges(), Cayenne will use
> > >> your key instead of trying to generate one.
> > >>
> > >> mrg
> > >>
> > >>
> > >> On Thu, Jul 30, 2009 at 1:24 AM, Juergen
> > Saar<ju...@jsaar.org>
> > wrote:
> > >> > Hi all,
> > >> >
> > >> > I'm using cayenne within an old 4GL-Project
> > with meaningful Primary Keys.
> > >> >
> > >> > Is there a 'best practice' to get this keys
> > into the DataObject-Instance?
> > >> >
> > >> > Actually I've various trouble with this ...
> > >> >
> > >> >
> > >> > Any hint or code-sniplet would be helpful
> > ...
> > >> > -Juergen-
> > >> >
> > >>
> > >
> >
>
>
>
>

Re: The right way to populate meaningful keys

Posted by Michael Gentry <mg...@masslight.net>.
I think Juergen is dealing with an existing DB.  I think many people
have written of the meaningful PK problem, from the fact that the keys
might eventually change over time to the fact that the speed of the
joins is much worse for a varchar meaningful PK compared to an integer
key that is generated.


On Thu, Jul 30, 2009 at 12:03 PM, Eric Lazarus<er...@yahoo.com> wrote:
>
> (Reminder: Avoid meaningful keys when you have the choice, like anytime you are designing the database from scratch.
>
> Who wants to write the wikipedia article on the meaningful pointer problem...?)
>
> Eric
> +1 (917) 589-6579
>
>
> --- On Thu, 7/30/09, Michael Gentry <mg...@masslight.net> wrote:
>
>> From: Michael Gentry <mg...@masslight.net>
>> Subject: Re: The right way to populate meaningful keys
>> To: user@cayenne.apache.org
>> Date: Thursday, July 30, 2009, 11:01 AM
>> Hi Juergen,
>>
>> I suspect that you need to assign the key on the other side
>> of your
>> 1:1 relationship, too.  Another thing you could try
>> doing is using the
>> To Dep PK checkbox in the DbEntity Relationship panel to
>> see if
>> Cayenne will auto-copy your meaningful PK for you.
>>
>> http://cayenne.apache.org/doc/to-dep-pk-checkbox.html
>>
>> I'm not sure if the To Dep PK will work that way, but it is
>> worth a
>> try.  If you assign all the keys, though, it should
>> work.
>>
>>
>> On Thu, Jul 30, 2009 at 10:53 AM, Juergen Saar<ju...@jsaar.org>
>> wrote:
>> > This was my way  ...
>> > But I ran in deep trouble with the ObjectId ... this
>> seems not to be
>> > sycronized
>> >
>> > My actual CayenneRuntimeException:
>> > Can't extract a master key. Missing key (esd_abteil),
>> master ID
>> > (<ObjectId:EsSend, TEMP:0000021E6A770001>)
>> >
>> > It belongs to a 1:1 Relation and the PK-Values in
>> source and target are
>> > correctly set.
>> > The Commit is interrupted and the Relation-Data are
>> not inserted to DB.
>> >
>> >
>> > In nearly all cases ... even when all data is inserted
>> in DB the following
>> > CayenneRuntimException is thrown:
>> > Temporary ID hasn't been replaced on
>> commit:{<ObjectId:EsSend,
>> > TEMP:0000022273C50001>; new; ...}
>> >
>> > Any idea?
>> > -Juergen-
>> >
>> > PS: I'm using the Version 2.0.4
>> >
>> >
>> > 2009/7/30 Michael Gentry <mg...@masslight.net>
>> >
>> >> Cayenne, by default, doesn't map keys from the
>> DbEntity (database
>> >> definition) to the ObjEntity (Java definition),
>> but you can go into
>> >> the ObjEntity and add them and it should be fine.
>>  After you do that,
>> >> just call the set/get methods for the keys to
>> set/get them.  If you
>> >> set a key on a new object before you
>> commitChanges(), Cayenne will use
>> >> your key instead of trying to generate one.
>> >>
>> >> mrg
>> >>
>> >>
>> >> On Thu, Jul 30, 2009 at 1:24 AM, Juergen
>> Saar<ju...@jsaar.org>
>> wrote:
>> >> > Hi all,
>> >> >
>> >> > I'm using cayenne within an old 4GL-Project
>> with meaningful Primary Keys.
>> >> >
>> >> > Is there a 'best practice' to get this keys
>> into the DataObject-Instance?
>> >> >
>> >> > Actually I've various trouble with this ...
>> >> >
>> >> >
>> >> > Any hint or code-sniplet would be helpful
>> ...
>> >> > -Juergen-
>> >> >
>> >>
>> >
>>
>
>
>
>

Re: The right way to populate meaningful keys

Posted by Juergen Saar <ju...@jsaar.org>.
Pretty hint ...

I moved to-dep-pk from 'source' to 'target' of the relation ... it worked

A little strage because the join-fields were filled in on both sides

It is a typical optional Information that ist attached by the 1:1 relation
so to-dep-pk would be right on both sides of the relation.

Thanx ...
-Juergen-


2009/7/30 Michael Gentry <mg...@masslight.net>

> Hi Juergen,
>
> I suspect that you need to assign the key on the other side of your
> 1:1 relationship, too.  Another thing you could try doing is using the
> To Dep PK checkbox in the DbEntity Relationship panel to see if
> Cayenne will auto-copy your meaningful PK for you.
>
> http://cayenne.apache.org/doc/to-dep-pk-checkbox.html
>
> I'm not sure if the To Dep PK will work that way, but it is worth a
> try.  If you assign all the keys, though, it should work.
>
>
> On Thu, Jul 30, 2009 at 10:53 AM, Juergen Saar<ju...@jsaar.org> wrote:
> > This was my way  ...
> > But I ran in deep trouble with the ObjectId ... this seems not to be
> > sycronized
> >
> > My actual CayenneRuntimeException:
> > Can't extract a master key. Missing key (esd_abteil), master ID
> > (<ObjectId:EsSend, TEMP:0000021E6A770001>)
> >
> > It belongs to a 1:1 Relation and the PK-Values in source and target are
> > correctly set.
> > The Commit is interrupted and the Relation-Data are not inserted to DB.
> >
> >
> > In nearly all cases ... even when all data is inserted in DB the
> following
> > CayenneRuntimException is thrown:
> > Temporary ID hasn't been replaced on commit:{<ObjectId:EsSend,
> > TEMP:0000022273C50001>; new; ...}
> >
> > Any idea?
> > -Juergen-
> >
> > PS: I'm using the Version 2.0.4
> >
> >
> > 2009/7/30 Michael Gentry <mg...@masslight.net>
> >
> >> Cayenne, by default, doesn't map keys from the DbEntity (database
> >> definition) to the ObjEntity (Java definition), but you can go into
> >> the ObjEntity and add them and it should be fine.  After you do that,
> >> just call the set/get methods for the keys to set/get them.  If you
> >> set a key on a new object before you commitChanges(), Cayenne will use
> >> your key instead of trying to generate one.
> >>
> >> mrg
> >>
> >>
> >> On Thu, Jul 30, 2009 at 1:24 AM, Juergen Saar<ju...@jsaar.org> wrote:
> >> > Hi all,
> >> >
> >> > I'm using cayenne within an old 4GL-Project with meaningful Primary
> Keys.
> >> >
> >> > Is there a 'best practice' to get this keys into the
> DataObject-Instance?
> >> >
> >> > Actually I've various trouble with this ...
> >> >
> >> >
> >> > Any hint or code-sniplet would be helpful ...
> >> > -Juergen-
> >> >
> >>
> >
>

Re: The right way to populate meaningful keys

Posted by Eric Lazarus <er...@yahoo.com>.
(Reminder: Avoid meaningful keys when you have the choice, like anytime you are designing the database from scratch.

Who wants to write the wikipedia article on the meaningful pointer problem...?) 

Eric
+1 (917) 589-6579


--- On Thu, 7/30/09, Michael Gentry <mg...@masslight.net> wrote:

> From: Michael Gentry <mg...@masslight.net>
> Subject: Re: The right way to populate meaningful keys
> To: user@cayenne.apache.org
> Date: Thursday, July 30, 2009, 11:01 AM
> Hi Juergen,
> 
> I suspect that you need to assign the key on the other side
> of your
> 1:1 relationship, too.  Another thing you could try
> doing is using the
> To Dep PK checkbox in the DbEntity Relationship panel to
> see if
> Cayenne will auto-copy your meaningful PK for you.
> 
> http://cayenne.apache.org/doc/to-dep-pk-checkbox.html
> 
> I'm not sure if the To Dep PK will work that way, but it is
> worth a
> try.  If you assign all the keys, though, it should
> work.
> 
> 
> On Thu, Jul 30, 2009 at 10:53 AM, Juergen Saar<ju...@jsaar.org>
> wrote:
> > This was my way  ...
> > But I ran in deep trouble with the ObjectId ... this
> seems not to be
> > sycronized
> >
> > My actual CayenneRuntimeException:
> > Can't extract a master key. Missing key (esd_abteil),
> master ID
> > (<ObjectId:EsSend, TEMP:0000021E6A770001>)
> >
> > It belongs to a 1:1 Relation and the PK-Values in
> source and target are
> > correctly set.
> > The Commit is interrupted and the Relation-Data are
> not inserted to DB.
> >
> >
> > In nearly all cases ... even when all data is inserted
> in DB the following
> > CayenneRuntimException is thrown:
> > Temporary ID hasn't been replaced on
> commit:{<ObjectId:EsSend,
> > TEMP:0000022273C50001>; new; ...}
> >
> > Any idea?
> > -Juergen-
> >
> > PS: I'm using the Version 2.0.4
> >
> >
> > 2009/7/30 Michael Gentry <mg...@masslight.net>
> >
> >> Cayenne, by default, doesn't map keys from the
> DbEntity (database
> >> definition) to the ObjEntity (Java definition),
> but you can go into
> >> the ObjEntity and add them and it should be fine.
>  After you do that,
> >> just call the set/get methods for the keys to
> set/get them.  If you
> >> set a key on a new object before you
> commitChanges(), Cayenne will use
> >> your key instead of trying to generate one.
> >>
> >> mrg
> >>
> >>
> >> On Thu, Jul 30, 2009 at 1:24 AM, Juergen
> Saar<ju...@jsaar.org>
> wrote:
> >> > Hi all,
> >> >
> >> > I'm using cayenne within an old 4GL-Project
> with meaningful Primary Keys.
> >> >
> >> > Is there a 'best practice' to get this keys
> into the DataObject-Instance?
> >> >
> >> > Actually I've various trouble with this ...
> >> >
> >> >
> >> > Any hint or code-sniplet would be helpful
> ...
> >> > -Juergen-
> >> >
> >>
> >
> 


      

Re: The right way to populate meaningful keys

Posted by Michael Gentry <mg...@masslight.net>.
Hi Juergen,

I suspect that you need to assign the key on the other side of your
1:1 relationship, too.  Another thing you could try doing is using the
To Dep PK checkbox in the DbEntity Relationship panel to see if
Cayenne will auto-copy your meaningful PK for you.

http://cayenne.apache.org/doc/to-dep-pk-checkbox.html

I'm not sure if the To Dep PK will work that way, but it is worth a
try.  If you assign all the keys, though, it should work.


On Thu, Jul 30, 2009 at 10:53 AM, Juergen Saar<ju...@jsaar.org> wrote:
> This was my way  ...
> But I ran in deep trouble with the ObjectId ... this seems not to be
> sycronized
>
> My actual CayenneRuntimeException:
> Can't extract a master key. Missing key (esd_abteil), master ID
> (<ObjectId:EsSend, TEMP:0000021E6A770001>)
>
> It belongs to a 1:1 Relation and the PK-Values in source and target are
> correctly set.
> The Commit is interrupted and the Relation-Data are not inserted to DB.
>
>
> In nearly all cases ... even when all data is inserted in DB the following
> CayenneRuntimException is thrown:
> Temporary ID hasn't been replaced on commit:{<ObjectId:EsSend,
> TEMP:0000022273C50001>; new; ...}
>
> Any idea?
> -Juergen-
>
> PS: I'm using the Version 2.0.4
>
>
> 2009/7/30 Michael Gentry <mg...@masslight.net>
>
>> Cayenne, by default, doesn't map keys from the DbEntity (database
>> definition) to the ObjEntity (Java definition), but you can go into
>> the ObjEntity and add them and it should be fine.  After you do that,
>> just call the set/get methods for the keys to set/get them.  If you
>> set a key on a new object before you commitChanges(), Cayenne will use
>> your key instead of trying to generate one.
>>
>> mrg
>>
>>
>> On Thu, Jul 30, 2009 at 1:24 AM, Juergen Saar<ju...@jsaar.org> wrote:
>> > Hi all,
>> >
>> > I'm using cayenne within an old 4GL-Project with meaningful Primary Keys.
>> >
>> > Is there a 'best practice' to get this keys into the DataObject-Instance?
>> >
>> > Actually I've various trouble with this ...
>> >
>> >
>> > Any hint or code-sniplet would be helpful ...
>> > -Juergen-
>> >
>>
>

Re: The right way to populate meaningful keys

Posted by Juergen Saar <ju...@jsaar.org>.
This was my way  ...
But I ran in deep trouble with the ObjectId ... this seems not to be
sycronized

My actual CayenneRuntimeException:
Can't extract a master key. Missing key (esd_abteil), master ID
(<ObjectId:EsSend, TEMP:0000021E6A770001>)

It belongs to a 1:1 Relation and the PK-Values in source and target are
correctly set.
The Commit is interrupted and the Relation-Data are not inserted to DB.


In nearly all cases ... even when all data is inserted in DB the following
CayenneRuntimException is thrown:
Temporary ID hasn't been replaced on commit:{<ObjectId:EsSend,
TEMP:0000022273C50001>; new; ...}

Any idea?
-Juergen-

PS: I'm using the Version 2.0.4


2009/7/30 Michael Gentry <mg...@masslight.net>

> Cayenne, by default, doesn't map keys from the DbEntity (database
> definition) to the ObjEntity (Java definition), but you can go into
> the ObjEntity and add them and it should be fine.  After you do that,
> just call the set/get methods for the keys to set/get them.  If you
> set a key on a new object before you commitChanges(), Cayenne will use
> your key instead of trying to generate one.
>
> mrg
>
>
> On Thu, Jul 30, 2009 at 1:24 AM, Juergen Saar<ju...@jsaar.org> wrote:
> > Hi all,
> >
> > I'm using cayenne within an old 4GL-Project with meaningful Primary Keys.
> >
> > Is there a 'best practice' to get this keys into the DataObject-Instance?
> >
> > Actually I've various trouble with this ...
> >
> >
> > Any hint or code-sniplet would be helpful ...
> > -Juergen-
> >
>

Re: The right way to populate meaningful keys

Posted by Michael Gentry <mg...@masslight.net>.
Cayenne, by default, doesn't map keys from the DbEntity (database
definition) to the ObjEntity (Java definition), but you can go into
the ObjEntity and add them and it should be fine.  After you do that,
just call the set/get methods for the keys to set/get them.  If you
set a key on a new object before you commitChanges(), Cayenne will use
your key instead of trying to generate one.

mrg


On Thu, Jul 30, 2009 at 1:24 AM, Juergen Saar<ju...@jsaar.org> wrote:
> Hi all,
>
> I'm using cayenne within an old 4GL-Project with meaningful Primary Keys.
>
> Is there a 'best practice' to get this keys into the DataObject-Instance?
>
> Actually I've various trouble with this ...
>
>
> Any hint or code-sniplet would be helpful ...
> -Juergen-
>