openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Manipulating sequence generated value before persisting entities
Date Wed, 24 Nov 2010 16:58:56 GMT
Hi,

The lifecycle callbacks probably aren't the right place to do what you want.
Generated values are made available in the PostPersist callback which isn't
suitable for your purposes. The spec doesn't explicitly state that you
cannot make them available in PrePersist but it wouldn't be something that
you could rely on.

You might be better off removing the @GeneratedValue annotation and
obtaining the sequence value manually - and manipulating the value before
calling the setter.

You might be able to get something to work with OpenJPA's Transaction Events
[1]. There's not a lot of documentation on them, and I don't know if you'll
be able to modify the entities before they're written to the database.
They're also a bit brittle from the little I've seen.

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_runtime_pm_event

Hope this helps,
-mike

On Tue, Nov 23, 2010 at 6:12 PM, nasseria1 <nasser.fard@gmail.com> wrote:

>
> Hi all,
>
> We want to use a custom sequence generator so that manipulating its
> generated value before persisting it into database would be possible.
>
> For example, the generated value for a sample primary key that used
> database
> sequence generator is 205 and before persisting the entity, we just want to
> manipulate the generated value using a specified algorithm. As it's clear,
> I
> want to use the database sequence, but modifying the generated value is the
> main requirement.
>
> To resolve this, I inspected the generated value in @PrePersist entity
> callback, but it did not include the generated value.
>
> I would appreciate for any ideas
> Nasser
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Manipulating-sequence-generated-value-before-persisting-entities-tp5768846p5768846.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message