I have been using strategy=GenerationType.TABLE
for my project entities for some years. This works really well and it is not very common to get errors. But from time to time, some procedure has been unable to insert in the database and gets MySQLIntegrityConstraintViolationException: Duplicate entry
error with low concurrency. The big issue is when somehow that table remains bugged and fails every try, trying to insert using the same ID number all the time.
In the end, I have to restart the server to solve the issue.
By default, eclipselink uses allocationSize=50. I use the default, but however it doesnt seem to be just a concurrency problem because the server has not high concurrency, and later tries should work.
@Id
@TableGenerator(name="TABLE_GEN_TABLE1", table="sequence", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="table1")
@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN_TABLE1")
@Column(name = "id")
long id;
I also have sequence connection pool activated in persistance.xml
<property name="eclipselink.jdbc.sequence-connection-pool" value="true"/>