Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Sequences set via-triggers and the@SequenceGenerator annotation

Interesting, so you're basically creating your own custom platform
that acts like oracle but doesn't support sequence objects.

Thanks for your answer, it's good to know I could do it that way if I have to.

 I think the more complete and safe way would be to re-do the triggers
so that they're aware of someone setting a PK manually, I smell a
regex :)

Thanks again,
Tim

On Fri, Oct 17, 2008 at 11:16 AM, Andrei Ilitchev
<andrei.ilitchev@xxxxxxxxxx> wrote:
> If ALL the tables in persistence unit are equipped with the triggers then
> it's easier to subclass the database platform:
> class OraclePlatformWithIdentity extends OraclePlatform {
>   public OraclePlatformWithIdentity{
>     super();
>     setSupportsIdentity(true);
>   }
>   public boolean supportsSequenceObjects() {
>     return false;
>   }
> }
> Pass the subclassed platform name through persistence unit property:
> eclipselink.target-database  -> "OraclePlatformWithIdentity"
>
>
> Alternatively, if only SOME tables use triggers and other use sequence
> objects in the original way then you need to use SessionCustomizer:
> // set the flag in OraclePlatform indicating that it supports "Identity"
> OraclePlatform platform = (OraclePlatform)session.getLogin().getPlatform();
> platform.setSupportsIdentity(true);
> // change each sequence associated with table with a trigger to behave like
> Identity
> ((NativeSequence)platform.getSequence("SequenceToBeChanged")).setShouldUseIdentityIfPlatformSupports(true);
>
> Hope that helps,
> Andrei
>
> ----- Original Message -----
> From: "Tim Hollosy" <hollosyt@xxxxxxxxx>
> To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
> Sent: Friday, October 17, 2008 9:14 AM
> Subject: [eclipselink-users] Sequences set via-triggers and
> the@SequenceGenerator annotation
>> Here's the situation.
>>
>> I have a database where the pk sequence for each table is set via an
>> insert trigger. All of these triggers are dumb, and don't check to
>> make sure the pk is not already set in the row before grabbing the
>> nextval and setting it.
>>
>> I discovered this problem while running some tests of doing cascade
>> persists, and my sequence and hence PK of a parent table was being
>> incremented twice. Once by EclipseLink a second time via the insert
>> trigger.
>>
>> Is there some sort of way I can tell EclipseLink to Post-Fetch the
>> sequence after the insert and figure out relationships that way or
>> would I be better off just biting the bullet and making all my
>> triggers more intelligent?
>>
>> Thanks,
>> Tim
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


Back to the top