Hi Henno,

Whether the table generator will be a performance bottleneck will depend on
your application.  If it is insert/persist heavy and/or has many clients
simultaneously persisting new entities, the table generator could become a
bottleneck. As you mentioned, increasing the allocation size will reduce
trips to the database and contention on the table.  Using a separate table
via a custom table generator can help remove contention on any single
table.  A custom table generator also provides the ability to reuse a single
table by using a different PK value for each generated id.  (ie.  each
generator has its own table row)  That can provide better performance and
help reduce the number of DB tables you need to manage.

Also, if you'd like to continue using the system/default table generator you
can change the default allocation size by setting this persistence property:

      <property name="openjpa.Sequence" value="table(Increment=1000)"/>

>> We have existing data that is migrated to the database schema generated
by OpenJPA. Am I correct that after migration I >> should initialize the
SEQUENCE_VALUE to the maximum over all entity id's?

Yes.  Initializing SEQUENCE_VALUE to a value larger than your current
maximum entity ID should do the trick.

hth,
-Jeremy

On Wed, Feb 23, 2011 at 3:37 AM, Henno Vermeulen <he...@huizemolenaar.nl>wrote:

> Hello,
>
> All of our entities inherit from "AbstractEntity" which is a
> MappedSuperclass that defines an automatically generated identity column of
> type Long. Because of issues we are having with GenerationType.IDENTITY (
> https://issues.apache.org/jira/browse/OPENJPA-1949) I would like to switch
> to GenerationType.TABLE.
>
> When I annotate the id column in our mapped super class as
>
>            @Id
>            @GeneratedValue(strategy = GenerationType.TABLE)
>            private Long id;
>
> OpenJPA creates a sequence table with only one row (with ID 0). This means
> that all our entities will share this sequence to generate new id's. This is
> not a problem for our application, but I was wondering if there are any
> performance issues with this. Would this be solved by defining my own
> tablegenerator with an allocationSize of something like 1000?
>
> We have existing data that is migrated to the database schema generated by
> OpenJPA. Am I correct that after migration I should initialize the
> SEQUENCE_VALUE to the maximum over all entity id's?
>
> (I guess it can also be solved by pulling up the id column so that all our
> entities have to define it's own id and use the same generator table. This
> gives a lot of unnecessary code duplication while our design choice that all
> of our entities have a synthetic id works perfectly fine for us. We use this
> in many places with our notification, caching and application level lock
> system.)
>
> Henno
>
>

Reply via email to