Extending this question Why does eclipselink consume the whole allocationSize each time it's rebooted?
I would like to know what a proper solution for this problem is, the only answer in that post suggests switching to an IDENTITY
strategy which i have done but i cannot see the changes. The allocation size of 50 is still in affect. Does anyone have any examples on how to generate sequential identifiers (1, 2, 3) based on each entity (table) and not a single sequence accessible by all tables?
Asked
Active
Viewed 1,575 times
0
1 Answers
0
You have the TableGenerator annotation for that purpose.
@Entity
public class Employee {
@Id
@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
valueColumnName="SEQ_COUNT", pkColumnValue="EMP_SEQ", allocationSize = 500, initialValue = 1)
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
private long id;
...
}
@Entity
public class PaySlip {
@Id
@TableGenerator(name="SECOND_TABLE_GEN", table="SECOND_SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
valueColumnName="SEQ_COUNT", pkColumnValue="SECOND_EMP_SEQ", allocationSize = 500, initialValue = 1)
@GeneratedValue(strategy=GenerationType.TABLE, generator="SECOND_TABLE_GEN")
private long id;
...
}
Make sure that all the name/*table* and pkColumnValue fields value are unique.
Reference

Kaalras
- 1,073
- 10
- 13
-
This does not fix the allocation size = 50 problem, i am able to create separate sequence tables for each entity but i want to get sequential numbering for new records (1, 2, 3... instead of 1, 51 ...) – Warz May 26 '12 at 23:01
-
sorry to keep furthering the question but i noticed you added an 'initial value' to TableGenerator, i have as a requirement to start the first id at 100000 and increase from there (100001, 100002 ...) can i set it there or will that break anything? – Warz May 27 '12 at 02:03
-
i had to set allocationSize = 1 if i want to get sequential ordering otherwise with what you have posted it starts as (1, 501 .... – Warz May 27 '12 at 03:00
-
Drop the allocationSize parameter and set initialValue = 100000. That works well. – Kaalras May 27 '12 at 10:01
-
by default EclipseLink sets the value of allocationSize = 50 if you dont set it to 1 then it will increment the value by 50, i heard it is a performance issue by setting it to 1 but dont know why. I will accept this answer as i am able to get sequence tables for each entity and set initial value but i have to set allocation size = 1 if i want to get sequential identifiers – Warz May 27 '12 at 16:24
-
It's strange i've tested it with eclipselink 2.3 and it's working just fine. Could you post your code ? – Kaalras May 28 '12 at 13:38