You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mike Kienenberger <mk...@gmail.com> on 2006/05/23 04:27:15 UTC
auto-incrementing non-primary key field value needed
What's the best way to go about generating a non-primary-key
auto-incrementing field value (unique, but eventually will be
meaningful to the end users)?
The database is Oracle (although I'd like it to work on HSQLDB too).
Do I have to do this with a separate out-of-transaction database
query, or is there some way I can make Cayenne assign a sequence value
to this column?
Re: auto-incrementing non-primary key field value needed
Posted by Marcin Skladaniec <ma...@ish.com.au>.
Thank you !
Marcin
On 24/05/2006, at 9:47 AM, Andrus Adamchik wrote:
> I was talking about PkGenerator.generatePkForDbEntity(DataNode,
> DbEntity) method (PkGenerator instance is owned by DbAdapter that
> is owned by DataNode). How you configure it is up to you. If you
> don't care about the gaps in values, and only care about them being
> unique, you can pass the real DbEntity to this method; if you want
> a separate sequence, you may fake a "synthetic" DbEntity and add an
> extra row to AUTO_PK_SUPPORT (or create an extra DB sequence if you
> are on oracle or postgres).
>
> Andrus
>
>
> On May 23, 2006, at 7:39 PM, Marcin Skladaniec wrote:
>> On 24/05/2006, at 9:20 AM, Andrus Adamchik wrote:
>>
>>>
>>> On May 22, 2006, at 10:27 PM, Mike Kienenberger wrote:
>>>
>>>> What's the best way to go about generating a non-primary-key
>>>> auto-incrementing field value (unique, but eventually will be
>>>> meaningful to the end users)?
>>>>
>>>> The database is Oracle (although I'd like it to work on HSQLDB
>>>> too).
>>>>
>>>> Do I have to do this with a separate out-of-transaction database
>>>> query, or is there some way I can make Cayenne assign a sequence
>>>> value
>>>> to this column?
>>>
>>> Cayenne won't assign values to non-pk columns, but you can still
>>> reuse the Cayenne PK mechanism to obtain a sequence of values and
>>> set the values manually.
>>>
>>> Andrus
>>
>> Andrus, could you explain a bit how to use Cayenne PK mechanism ?
>> Would that require creating extra row in AUTO_PK_SUPPORT ? I would
>> like to use auto-incrementation on non PK field too.
>>
>> Thank you.
>> Marcin
>>
>> -------------------------->
>> ish
>> http://www.ish.com.au
>> Level 1, 30 Wilson Street Newtown 2042 Australia
>> phone +61 2 9550 5001 fax +61 2 9550 4001
>
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001
Re: auto-incrementing non-primary key field value needed
Posted by Andrus Adamchik <an...@objectstyle.org>.
I was talking about PkGenerator.generatePkForDbEntity(DataNode,
DbEntity) method (PkGenerator instance is owned by DbAdapter that is
owned by DataNode). How you configure it is up to you. If you don't
care about the gaps in values, and only care about them being unique,
you can pass the real DbEntity to this method; if you want a separate
sequence, you may fake a "synthetic" DbEntity and add an extra row to
AUTO_PK_SUPPORT (or create an extra DB sequence if you are on oracle
or postgres).
Andrus
On May 23, 2006, at 7:39 PM, Marcin Skladaniec wrote:
> On 24/05/2006, at 9:20 AM, Andrus Adamchik wrote:
>
>>
>> On May 22, 2006, at 10:27 PM, Mike Kienenberger wrote:
>>
>>> What's the best way to go about generating a non-primary-key
>>> auto-incrementing field value (unique, but eventually will be
>>> meaningful to the end users)?
>>>
>>> The database is Oracle (although I'd like it to work on HSQLDB too).
>>>
>>> Do I have to do this with a separate out-of-transaction database
>>> query, or is there some way I can make Cayenne assign a sequence
>>> value
>>> to this column?
>>
>> Cayenne won't assign values to non-pk columns, but you can still
>> reuse the Cayenne PK mechanism to obtain a sequence of values and
>> set the values manually.
>>
>> Andrus
>
> Andrus, could you explain a bit how to use Cayenne PK mechanism ?
> Would that require creating extra row in AUTO_PK_SUPPORT ? I would
> like to use auto-incrementation on non PK field too.
>
> Thank you.
> Marcin
>
> -------------------------->
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001 fax +61 2 9550 4001
Re: auto-incrementing non-primary key field value needed
Posted by Marcin Skladaniec <ma...@ish.com.au>.
On 24/05/2006, at 9:20 AM, Andrus Adamchik wrote:
>
> On May 22, 2006, at 10:27 PM, Mike Kienenberger wrote:
>
>> What's the best way to go about generating a non-primary-key
>> auto-incrementing field value (unique, but eventually will be
>> meaningful to the end users)?
>>
>> The database is Oracle (although I'd like it to work on HSQLDB too).
>>
>> Do I have to do this with a separate out-of-transaction database
>> query, or is there some way I can make Cayenne assign a sequence
>> value
>> to this column?
>
> Cayenne won't assign values to non-pk columns, but you can still
> reuse the Cayenne PK mechanism to obtain a sequence of values and
> set the values manually.
>
> Andrus
Andrus, could you explain a bit how to use Cayenne PK mechanism ?
Would that require creating extra row in AUTO_PK_SUPPORT ? I would
like to use auto-incrementation on non PK field too.
Thank you.
Marcin
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001
Re: auto-incrementing non-primary key field value needed
Posted by Andrus Adamchik <an...@objectstyle.org>.
On May 22, 2006, at 10:27 PM, Mike Kienenberger wrote:
> What's the best way to go about generating a non-primary-key
> auto-incrementing field value (unique, but eventually will be
> meaningful to the end users)?
>
> The database is Oracle (although I'd like it to work on HSQLDB too).
>
> Do I have to do this with a separate out-of-transaction database
> query, or is there some way I can make Cayenne assign a sequence value
> to this column?
Cayenne won't assign values to non-pk columns, but you can still
reuse the Cayenne PK mechanism to obtain a sequence of values and set
the values manually.
Andrus