• Post Reply Bookmark Topic Watch Topic
  • New Topic

more information about automatic ID creation

 
Himai Minh
Ranch Hand
Posts: 1400
8
  • 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",
initialValue=0,
allocationSize = 100)
@Id
@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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!