You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by emmanuel2009 <cl...@gmail.com> on 2009/07/06 11:23:51 UTC
@SequenceGenerator allocationSize
Hi guys,
I got some doubts in allocationSize. My project is a multi-application
environment. I'm giving SequenceGenerator with allocationSize=10.
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="myseq")
@SequenceGenerator(name="myseq",sequenceName="MY_SEQ",allocationSize=10)
private long id;
Suppose my first application say app1 will access the DB and got 10
available id's. My second application say aap2 will also get same id. when
app1 will insert it insert id 100 by the time app2 will insert it also tries
to insert 100. it will cause problem.
What is the use of allocationSize then.
--
View this message in context: http://n2.nabble.com/%40SequenceGenerator-allocationSize-tp3212122p3212122.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: @SequenceGenerator allocationSize
Posted by Michael Dick <mi...@gmail.com>.
Hi Emmanuel,
The scenario you've described shouldn't happen.
When you create the first EntityManager it will reserve the next 10 values
from your sequence generator (1 through 10). The second EntityManager gets
the next 10 values (11 through 20). This call to reserve sequence values
from the database is atomic and you should never see two EMs using the same
sequence value.
I've only tried this with PostgreSQL but it looks like it's working for me.
Do you have a testcase that shows the behavior you've described?
-mike
On Mon, Jul 6, 2009 at 4:23 AM, emmanuel2009 <cl...@gmail.com>wrote:
>
> Hi guys,
>
> I got some doubts in allocationSize. My project is a multi-application
> environment. I'm giving SequenceGenerator with allocationSize=10.
>
> @Id
> @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="myseq")
> @SequenceGenerator(name="myseq",sequenceName="MY_SEQ",allocationSize=10)
> private long id;
>
> Suppose my first application say app1 will access the DB and got 10
> available id's. My second application say aap2 will also get same id. when
> app1 will insert it insert id 100 by the time app2 will insert it also
> tries
> to insert 100. it will cause problem.
>
> What is the use of allocationSize then.
>
>
> --
> View this message in context:
> http://n2.nabble.com/%40SequenceGenerator-allocationSize-tp3212122p3212122.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>