You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Garimella Srinivas <ga...@yahoo.co.in> on 2010/04/01 10:55:46 UTC
Id generation - regarding
I have an entity PhoneNo with @id as follows
@Id
@TableGenerator(name="PhoneBook_IDGen", table="ID_GEN_TABLE", pkColumnName="Gen_Name", valueColumnName="Gen_ID_Value", pkColumnValue="PhoneBook_IDGen", initialValue = 1, allocationSize = 100)
@GeneratedValue(strategy=GenerationType.TABLE,generator = "PhoneBook_IDGen")
public long getId() {
return this.id;
}
Every time the server/openjpa is started the id table is updated and the id starts with an icrement of 100. If I have 2 asthe last id id for first run the second run starts with 100.
However the the id needs to be 3 for the next entity. Is some thing wrong?
Thanks
G Srinivas
Re: Id generation - regarding
Posted by Garimella Srinivas <ga...@yahoo.co.in>.
Thank you for immediate reply. Checked the pointers. I am using Derby which does not support Sequencing yet. However I got the required result by changing athe allocation size to 1.
Thanks
G Srinivas
--- On Thu, 4/1/10, No1UNo <je...@jerrycarter.org> wrote:
From: No1UNo <je...@jerrycarter.org>
Subject: Re: Id generation - regarding
To: users@openjpa.apache.org
Date: Thursday, April 1, 2010, 4:44 PM
This is more or less what you'd expect. The TableGenerator is preallocating a block of 'allocationSize' which is 100 in your case. Requesting several IDs should give sequential results when requested from one EntityManager. Starting the application and restarting will result in another allocation.
The result is that your IDs will not be sequential. This may not meet your initial expectations but is entirely fine.
An alternative is to use a sequence generator if your database supports it.
You might find that this [1] article at Wikibooks provides a good explanation.
[1] http:http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Table_sequencing
On Apr 1, 2010, at 4:56 AM, Garimella Srinivas [via OpenJPA] wrote:
> I have an entity PhoneNo with @id as follows
> @Id
> @TableGenerator(name="PhoneBook_IDGen", table="ID_GEN_TABLE", pkColumnName="Gen_Name", valueColumnName="Gen_ID_Value", pkColumnValue="PhoneBook_IDGen", initialValue = 1, allocationSize = 100)
>
> @GeneratedValue(strategy=GenerationType.TABLE,generator = "PhoneBook_IDGen")
> public long getId() {
> return this.id;
> }
>
>
> Every time the server/openjpa is started the id table is updated and the id starts with an icrement of 100. If I have 2 asthe last id id for first run the second run starts with 100.
>
> However the the id needs to be 3 for the next entity. Is some thing wrong?
> Thanks
> G Srinivas
>
>
>
>
>
> View message @ http://n2.nabble.com/Id-generation-regarding-tp4835934p4835934.html
> To start a new topic under OpenJPA Users, email ml-node+208411-1595610943-93721@n2.nabble.com
> To unsubscribe from OpenJPA Users, click here.
>
--
View this message in context: http://n2.nabble.com/Id-generation-regarding-tp4835934p4836409.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Id generation - regarding
Posted by No1UNo <je...@jerrycarter.org>.
This is more or less what you'd expect. The TableGenerator is preallocating a block of 'allocationSize' which is 100 in your case. Requesting several IDs should give sequential results when requested from one EntityManager. Starting the application and restarting will result in another allocation.
The result is that your IDs will not be sequential. This may not meet your initial expectations but is entirely fine.
An alternative is to use a sequence generator if your database supports it.
You might find that this [1] article at Wikibooks provides a good explanation.
[1] http:http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Table_sequencing
On Apr 1, 2010, at 4:56 AM, Garimella Srinivas [via OpenJPA] wrote:
> I have an entity PhoneNo with @id as follows
> @Id
> @TableGenerator(name="PhoneBook_IDGen", table="ID_GEN_TABLE", pkColumnName="Gen_Name", valueColumnName="Gen_ID_Value", pkColumnValue="PhoneBook_IDGen", initialValue = 1, allocationSize = 100)
>
> @GeneratedValue(strategy=GenerationType.TABLE,generator = "PhoneBook_IDGen")
> public long getId() {
> return this.id;
> }
>
>
> Every time the server/openjpa is started the id table is updated and the id starts with an icrement of 100. If I have 2 asthe last id id for first run the second run starts with 100.
>
> However the the id needs to be 3 for the next entity. Is some thing wrong?
> Thanks
> G Srinivas
>
>
>
>
>
> View message @ http://n2.nabble.com/Id-generation-regarding-tp4835934p4835934.html
> To start a new topic under OpenJPA Users, email ml-node+208411-1595610943-93721@n2.nabble.com
> To unsubscribe from OpenJPA Users, click here.
>
--
View this message in context: http://n2.nabble.com/Id-generation-regarding-tp4835934p4836409.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.