You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Malte <ma...@googlemail.com> on 2013/08/18 20:06:21 UTC
Custom ID Generator
Hi !
I'm new to JPA (and OpenJPA). For a new project i consider to use
OpenJPA as the persistence layer. During my investigations, I came
across a problem.
The existing system uses a table id generator. The ID saved in the
id-table is always the last used id. The OpenJPA table-id-generator
assumes that this is the next available id. I can't change the behaviour
of the old system, so I'm looking for a solution in the OpenJPA System.
I've been looking for a way to implement a custom id generator, but i
can't find any working example. Is it even possible to implement a
custom generator?
Regards
Malte
Re: Custom ID Generator
Posted by Dmitry Pavlov <id...@ufanet.ru>.
Hi Malte,
The simplest solution is to use your old ID generator or to write new
service for ID generation which will be using necessary logic, then
instead of using OpenJPA build-in generators just set generated ID into
your object.
Dima
18.08.2013 14:06, Malte пишет:
> Hi !
>
> I'm new to JPA (and OpenJPA). For a new project i consider to use
> OpenJPA as the persistence layer. During my investigations, I came
> across a problem.
>
> The existing system uses a table id generator. The ID saved in the
> id-table is always the last used id. The OpenJPA table-id-generator
> assumes that this is the next available id. I can't change the
> behaviour of the old system, so I'm looking for a solution in the
> OpenJPA System.
>
> I've been looking for a way to implement a custom id generator, but i
> can't find any working example. Is it even possible to implement a
> custom generator?
>
> Regards
> Malte
>
>
Re: Custom ID Generator
Posted by Kevin Sutter <kw...@gmail.com>.
Hi Malte,
Welcome to OpenJPA!
Maybe this is old information since you have already been experimenting
with the id generation, but I would first point you at this information.
Basic id generation is documented here:
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#jpa_overview_meta_gen
>From here, there is some information on the various built-in generators:
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_sequence
Since it sounds like you have a unique case for the table generator, you
might want to consider extending the OpenJPA table generator and substitute
your unique processing:
*You can use JPA SequenceGenerators to describe any built-in Seqs or your
own Seq implementation. Set the sequenceName attribute to a plugin string
describing your choice. *
* *
* *
* If specifying your own class name, you must include parentheses at the
end of the class name, even if you have no plugin properties to configure.
(E.g., sequenceName="com.example.SeqImpl()". *
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#jpa_overview_mapping_sequence
Hope this helps!
Kevin
On Sun, Aug 18, 2013 at 1:06 PM, Malte <ma...@googlemail.com> wrote:
> Hi !
>
> I'm new to JPA (and OpenJPA). For a new project i consider to use OpenJPA
> as the persistence layer. During my investigations, I came across a problem.
>
> The existing system uses a table id generator. The ID saved in the
> id-table is always the last used id. The OpenJPA table-id-generator assumes
> that this is the next available id. I can't change the behaviour of the old
> system, so I'm looking for a solution in the OpenJPA System.
>
> I've been looking for a way to implement a custom id generator, but i
> can't find any working example. Is it even possible to implement a custom
> generator?
>
> Regards
> Malte
>