• Post Reply Bookmark Topic Watch Topic
  • New Topic

more information about automatic ID creation  RSS feed

Himai Minh
Ranch Hand
Posts: 1572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, for everyone's information, I helped fix a problem in the automatic ID creation at http://www.thejavageek.com/2014/01/14/automatic-id-creation-using-jpa-table-generator/#comment-55111.

In the javageek DB do these:
create table id_gen ( gen_name VARCHAR(80), gen_val INT (11), Primary Key (gen_name));
insert into id_gen (gen_name, gen_val) values("Emp_Gen",0);

Fix the Employee :
@TableGenerator(name = "employee_gen", table = "id_gen",
pkColumnName = "gen_name",
pkColumnValue = "Emp_Gen",
valueColumnName = "gen_val",
allocationSize = 100)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "employee_gen")
private int idEmployee;

Try to run that test case multiple times. Your id generated will be 101,201 ...

I spent a few hours on that. I hope this can help others to solve the problem why we get that problem.

Reference : https://community.oracle.com/thread/695906?tstart=0
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!