Re: Hibernate, web application and only one sequence for all primary keys - Mailing list pgsql-sql

From Kenneth Marshall
Subject Re: Hibernate, web application and only one sequence for all primary keys
Date
Msg-id 20090917145453.GC22802@it.is.rice.edu
Whole thread Raw
In response to Re: Hibernate, web application and only one sequence for all primary keys  (rawi <only4com@web.de>)
List pgsql-sql
On Thu, Sep 17, 2009 at 07:47:13AM -0700, rawi wrote:
> 
> 
> Leo Mannhart wrote:
> > 
> > Caveat: If you use the standard sequence generator in hibernate, it is
> > not using the postgres-sequence in the "usual" manner. hibernate itself
> > caches 50 ID's as sequence numbers by default. This means, hibernate
> > only does a select on the database sequence every 50 numbers. it
> > multyplies the database sequence by 50 to get the "real" sequence
> > number. it generates the sequence numbers in blocks of 50 numbers or
> > according to the sequence cache size.
> > That said, you would probably not see any performance bottlenecks
> > because of the sequence number generator in the database, even with
> > thousands of inserts per second.
> > 
> 
> Hi Leo, thank you for the explanation!
> 
> I don't know if it is that cool to lose up to 50 IDs on each session-end of
> Hibernate...
> And what do you suppose it would happen, if I set the cache size of
> Hibernate's own sequence (after generation) by hand to 1 instead of 50? I
> wouldn't need tausends of inserts per second...
> 
> Kind regards, Rawi
> 
Hi Rawi,

If hibernate manages its pool of 50, it can use much lighter-weight
processes than using a full SQL query to a database. I would recommend
leaving it be. You can afford to lose a few ids in 2**63.

Regards,
Ken


pgsql-sql by date:

Previous
From: Nico Mandery
Date:
Subject: Re: Rules, functions and RETURNING
Next
From: Kenneth Marshall
Date:
Subject: Re: extracting from epoch values in pgsql