Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] RE: Question on sequencing using TableGenerator

Hi Reinhard and Andrei,

Thanks for sharing the information.

I am planning to implement the custom sequencing logic for all our entities in order to generate the ids upfront. The ids are required in order to capture audit details (changes) for an entity. When we traverse deep in the entity hierarchy I require comparison to be done on the objects in a child entity list etc. hence we require ids to be available before committing the data to the database.

As you have explained earlier I am planning to do an Update and then Select in the same transaction in order to get a pre allocated chunk of ids to be assigned for a JVM. Earlier I implemented this using "Select.....from SEQ_TABLE for update" and then update the SEQ_TABLE adding the chunk size. However this has started blocking sessions on the DB (oracle). I assume this would work all fine if not more than 4/5 JVMs try to generate the sequence. However in our development environment each developer would run an application instance and connect to the same DB. This is resulting in contention and the DB doesn't seem to be fast enough to quickly process the serial request for sequence generation.

I would keep you posted after I implement the sequencing logic the way you explaining but using spring jdbc template.

Thanks,
Shashi

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Reinhard Girstenbrei
Sent: Wednesday, July 21, 2010 2:48 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: [eclipselink-users] RE: Question on sequencing using TableGenerator

Hi Shashi,
Take a look at
http://wiki.eclipse.org/EclipseLink/Examples/JPA/CustomSequencing
You have not explained details about how you want to implement sequencing.
If your implement some sequence that is used by many thread/processes concurrently, then you are likely using a lock in the jvm and/or database which can lead to a lock contention problem which might cause bad insert performance. Therefore you lock for as short time as possible. TopLink sequences use autonomous transactions for the value generation and it uses sequence pre-allocation to lock for as little time as possible.

I hope that helps,
Reinhard

-----Original Message-----
From: eclipselink-users-request@xxxxxxxxxxx [mailto:eclipselink-users-request@xxxxxxxxxxx]
Sent: 20 July 2010 21:21
To: eclipselink-users@xxxxxxxxxxx
Subject: eclipselink-users Digest, Vol 35, Issue 23

Send eclipselink-users mailing list submissions to
        eclipselink-users@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
        https://dev.eclipse.org/mailman/listinfo/eclipselink-users
or, via email, send a message with subject or body 'help' to
        eclipselink-users-request@xxxxxxxxxxx

You can reach the person managing the list at
        eclipselink-users-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of eclipselink-users digest..."


Today's Topics:

   1. RE: Question on sequencing using TableGenerator (Shashikant Kale)
   2. Re: Question on sequencing using TableGenerator (Andrei Ilitchev)


----------------------------------------------------------------------

Message: 1
Date: Wed, 21 Jul 2010 00:17:27 +0530
From: Shashikant Kale <Shashikant.Kale@xxxxxxxxxxxxxxxx>
Subject: RE: [eclipselink-users] Question on sequencing using
        TableGenerator
To: EclipseLink User Discussions <eclipselink-users@xxxxxxxxxxx>
Message-ID: <FDCD1F56CDE47840ADD853365BBE7FEF04C4B5835A@indxchange03>
Content-Type: text/plain; charset="us-ascii"

Thanks a lot Andrei and Reinhard.

I asked the query below in order to understand the logic eclipselink handles sequence generation. I am planning to introduce our own sequence generator since we need IDs to be generated upfront before an entity is attached to the em.

I have an option to do this using spring jdbc. However being new to Spring JDBC I am unable to think of a similar implementation using Spring JDBC template wherein I can update preceding select and execute them both in the same transaction.

Can somebody please throw some light?

Regards,
Shashi

From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Andrei Ilitchev
Sent: Tuesday, July 20, 2010 11:24 PM
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] Question on sequencing using TableGenerator

In table sequence case, update precedes select and both are executed in the same transaction - so no dirty reads can happen.

On 20/07/2010 12:49 PM, Shashikant Kale wrote:
Hi,

We have been using eclipselink and I have a question wrt eclipselink in clustered environment. We are using TableGenerator for generating primary keys and we use the same sequence for all the entities.

e.g.

      @GeneratedValue(strategy = GenerationType.TABLE, generator = "default")
      @TableGenerator(
            name = "default",
            table = "ID_GENERATOR",
            pkColumnName = "ID_NAME",
            valueColumnName = "ID_VALUE",
            pkColumnValue = "default",
            initialValue = 1,
            allocationSize = 50
      )

However I have found that the Select query is fired without "For Update" clause. Wouldn't this cause issues due to dirty reads across multiple JVMs?

Kindly let me know how this is taken care.

Thanks,
Shashi






________________________________






_______________________________________________

eclipselink-users mailing list

eclipselink-users@xxxxxxxxxxx<mailto:eclipselink-users@xxxxxxxxxxx>

https://dev.eclipse.org/mailman/listinfo/eclipselink-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://dev.eclipse.org/mailman/private/eclipselink-users/attachments/20100720/236c32d8/attachment.html

------------------------------

Message: 2
Date: Tue, 20 Jul 2010 15:18:44 -0400
From: Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx>
Subject: Re: [eclipselink-users] Question on sequencing using
        TableGenerator
To: EclipseLink User Discussions <eclipselink-users@xxxxxxxxxxx>
Message-ID: <4C45F694.6030305@xxxxxxxxxx>
Content-Type: text/plain; charset="iso-8859-1"

Table sequence also generates most values before attaching to entities:
the higher allocationSize the rearer trips for the new sequence values
to the db.
It works like that: the first time the new object is created
update/select is executed Eclipselink stores allocationSize sequence
values with the last value being returned by the select, say
UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + allocationSize WHERE
SEQ_NAME = my_seq
SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = my_seq
if it has returned 100, then the sequence values to be used are 51,
52,...,100 (that assumes allocationSize==50)

If you still need a custom sequence I think the only way to do it would
be to derive a new class from
org.eclipse.persistence.sequencing.Sequence class (or one of its subclasses)
Then - because you are using the same sequence for all entities - I
would suggest using default (without any parameters)
  @GeneratedValue
annotation for entities that use the sequence;

and in SessionCustomizer override default sequence with your customary
sequence:
public MySequenceCustomizer implements SessionCustomizer {
    public void customize(Session session) throws Exception {
        session.getPlatform().setDefaultSequence(new MySequence());
    }
}


On 20/07/2010 2:47 PM, Shashikant Kale wrote:
>
> Thanks a lot Andrei and Reinhard.
>
>
>
> I asked the query below in order to understand the logic eclipselink
> handles sequence generation. I am planning to introduce our own
> sequence generator since we need IDs to be generated upfront before an
> entity is attached to the em.
>
>
>
> I have an option to do this using spring jdbc. However being new to
> Spring JDBC I am unable to think of a similar implementation using
> Spring JDBC template wherein I can update preceding select and execute
> them both in the same transaction.
>
>
>
> Can somebody please throw some light?
>
>
>
> Regards,
>
> Shashi
>
>
>
> *From:* eclipselink-users-bounces@xxxxxxxxxxx
> [mailto:eclipselink-users-bounces@xxxxxxxxxxx] *On Behalf Of *Andrei
> Ilitchev
> *Sent:* Tuesday, July 20, 2010 11:24 PM
> *To:* EclipseLink User Discussions
> *Subject:* Re: [eclipselink-users] Question on sequencing using
> TableGenerator
>
>
>
> In table sequence case, update precedes select and both are executed
> in the same transaction - so no dirty reads can happen.
>
> On 20/07/2010 12:49 PM, Shashikant Kale wrote:
>
> Hi,
>
>
>
> We have been using eclipselink and I have a question wrt eclipselink
> in clustered environment. We are using TableGenerator for generating
> primary keys and we use the same sequence for all the entities.
>
>
>
> e.g.
>
>
>
>       @GeneratedValue(strategy = GenerationType.TABLE, generator =
> "default")
>
>       @TableGenerator(
>
>             name = "default",
>
>             table = "ID_GENERATOR",
>
>             pkColumnName = "ID_NAME",
>
>             valueColumnName = "ID_VALUE",
>
>             pkColumnValue = "default",
>
>             initialValue = 1,
>
>             allocationSize = 50
>
>       )
>
>
>
> However I have found that the Select query is fired without "For
> Update" clause. Wouldn't this cause issues due to dirty reads across
> multiple JVMs?
>
>
>
> Kindly let me know how this is taken care.
>
>
>
> Thanks,
>
> Shashi
>
>
> ------------------------------------------------------------------------
>
>
>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx <mailto: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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://dev.eclipse.org/mailman/private/eclipselink-users/attachments/20100720/2e18897c/attachment.html

------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


End of eclipselink-users Digest, Vol 35, Issue 23
*************************************************
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top