I have an auto increment id field in spring boot class:
private long id //or it can be int, does not matter
I have also another field, which must be unique and alphanumeric, in same class:
private String code;
This field will have 6 alphanumeric (upper or lower case does not matter).
Is it possible to save this field auto while a new object created for that class, with such a method?
Long.toString("id_field_value",36);
Actually, it gives:
0 -> 0
1 -> 1
10 -> A
So, when first object is created, id will be 1.
Any suggestion?
For example, when i save Person object,
the id will be 1 automatically with JPA - hibarnate.
And also i want another field to be saved automatically, which is depending on id field.
So, id is 1, that string code must be 1 also.
Should i do this after creating object ? Like:
Person person = personRepository.save(person3); person.setCode(person.getId().toString);//or another functions