You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Neal Sanche <ne...@nsdev.org> on 2006/06/13 05:58:56 UTC

Key Generator Questions

Hi All,

Yesterday I had some fun with the sequence-table key generator. I had 
this fragment at the end of my Entity deployment plan.

      <pkgen:key-generator>
        <pkgen:sequence-table>
          <pkgen:table-name>sequence</pkgen:table-name>
          <pkgen:sequence-name>reminder</pkgen:sequence-name>
          <pkgen:batch-size>1</pkgen:batch-size>
        </pkgen:sequence-table>
      </pkgen:key-generator>

I know, I should increase my batch-size, but really I am only doing one 
at a time. But that's not my problem. Why doesn't the key-generator 
create the table if it doesn't already exist? It took me quite some time 
to figure out that it was looking for a table with two columns, one 
called 'name' and one called 'value'. Yeah, I know, it's pretty easy to 
guess it, but I couldn't find it documented. I'm sure I didn't look 
everywhere, and could have looked in the source code to find the columns.

Once I created my table, the application started throwing exceptions 
like crazy! It turned out the misleading 'Transaction already rolled 
back' errors were because the record in the table didn't exist. I'm sure 
it would be super easy to create the record if it wasn't already there, 
and start the numbering at 1. I'm just so surprised it doesn't already 
have this ability. I'm sure I'm missing something, right?

So, as far as I know, in order to get the key generator to work, I have 
to create the sequence table:

create table sequence (name varchar(240) not null primary key, value 
integer);

And then add the sequence key:

insert into sequence values ('reminder',1);

And then it'll go. Before that it just complains loudly and rolls back 
my transaction.

What am I missing?

Cheers.

-Neal



Re: Key Generator Questions

Posted by Aaron Mulder <am...@alumni.princeton.edu>.
There's some documentation on key generators here:

http://chariotsolutions.com/geronimo/ejb-structure.html#ejb-structure-entity-cmp-pkgen

It could probably use some examples, though.  :)

Thanks,
    Aaron

On 6/12/06, Neal Sanche <ne...@nsdev.org> wrote:
> Hi All,
>
> Yesterday I had some fun with the sequence-table key generator. I had
> this fragment at the end of my Entity deployment plan.
>
>       <pkgen:key-generator>
>         <pkgen:sequence-table>
>           <pkgen:table-name>sequence</pkgen:table-name>
>           <pkgen:sequence-name>reminder</pkgen:sequence-name>
>           <pkgen:batch-size>1</pkgen:batch-size>
>         </pkgen:sequence-table>
>       </pkgen:key-generator>
>
> I know, I should increase my batch-size, but really I am only doing one
> at a time. But that's not my problem. Why doesn't the key-generator
> create the table if it doesn't already exist? It took me quite some time
> to figure out that it was looking for a table with two columns, one
> called 'name' and one called 'value'. Yeah, I know, it's pretty easy to
> guess it, but I couldn't find it documented. I'm sure I didn't look
> everywhere, and could have looked in the source code to find the columns.
>
> Once I created my table, the application started throwing exceptions
> like crazy! It turned out the misleading 'Transaction already rolled
> back' errors were because the record in the table didn't exist. I'm sure
> it would be super easy to create the record if it wasn't already there,
> and start the numbering at 1. I'm just so surprised it doesn't already
> have this ability. I'm sure I'm missing something, right?
>
> So, as far as I know, in order to get the key generator to work, I have
> to create the sequence table:
>
> create table sequence (name varchar(240) not null primary key, value
> integer);
>
> And then add the sequence key:
>
> insert into sequence values ('reminder',1);
>
> And then it'll go. Before that it just complains loudly and rolls back
> my transaction.
>
> What am I missing?
>
> Cheers.
>
> -Neal
>
>
>

Re: Key Generator Questions

Posted by Gianny Damour <gi...@optusnet.com.au>.
Hi Neal,

Thanks for this feedabck. You are correct: it is pretty easy to write 
some initialization code to create a sequence table and insert a value. 
As a matter of fact, if you have a look to 
org.tranql.pkgenerator.SequenceTablePrimaryKeyGenerator.initSequenceTable() 
you can see that is is indeed super easy.

At some point, the sequence table was systematically initialized. As 
reported by GERONIMO-682 - "Automatic key generators too restrictive" 
(http://issues.apache.org/jira/browse/GERONIMO-682), this approach was 
not considered as appropriate. I think that when the primary key 
generators have been refactored this problem has been partially fixed.

Could you please open a JIRA to track the need of an optional element 
enabling sequence table generation?

Thanks,
Gianny

Neal Sanche wrote:

> Hi All,
>
> Yesterday I had some fun with the sequence-table key generator. I had 
> this fragment at the end of my Entity deployment plan.
>
>      <pkgen:key-generator>
>        <pkgen:sequence-table>
>          <pkgen:table-name>sequence</pkgen:table-name>
>          <pkgen:sequence-name>reminder</pkgen:sequence-name>
>          <pkgen:batch-size>1</pkgen:batch-size>
>        </pkgen:sequence-table>
>      </pkgen:key-generator>
>
> I know, I should increase my batch-size, but really I am only doing 
> one at a time. But that's not my problem. Why doesn't the 
> key-generator create the table if it doesn't already exist? It took me 
> quite some time to figure out that it was looking for a table with two 
> columns, one called 'name' and one called 'value'. Yeah, I know, it's 
> pretty easy to guess it, but I couldn't find it documented. I'm sure I 
> didn't look everywhere, and could have looked in the source code to 
> find the columns.
>
> Once I created my table, the application started throwing exceptions 
> like crazy! It turned out the misleading 'Transaction already rolled 
> back' errors were because the record in the table didn't exist. I'm 
> sure it would be super easy to create the record if it wasn't already 
> there, and start the numbering at 1. I'm just so surprised it doesn't 
> already have this ability. I'm sure I'm missing something, right?
>
> So, as far as I know, in order to get the key generator to work, I 
> have to create the sequence table:
>
> create table sequence (name varchar(240) not null primary key, value 
> integer);
>
> And then add the sequence key:
>
> insert into sequence values ('reminder',1);
>
> And then it'll go. Before that it just complains loudly and rolls back 
> my transaction.
>
> What am I missing?
>
> Cheers.
>
> -Neal
>
>
>
>