I'm trying to make a sequencial generator field in MySQL with JPA, the "prod_generator_id" must start in "1" for any entity. Example:
Here is my java object:
//this one is working fine, the id is unique...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "pro_id")
private Long id;
//here is the problem, must start in "1" by entity
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq")
@SequenceGenerator(name="seq", sequenceName="pro_id_tenancy", initialValue=1, allocationSize=1)
@Column(name = "pro_id_tenancy")
private Long idTenancyProjeto;
I'm using spring boot, but when I save the object, the idTenancyProjeto is going null.
The most simple solution I've found: Just count the number of products of that company, and add+1 in my product.save(), nothing more, is working. Thanks for all.