Skip to main content

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

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
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