I have the following entity:
@Entity
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private String uberField;
}
My intention is to make uberField contain a random digit (0-9) and concat it to the char '-' and the entity id. for example:
user with id:233 will receive uberField == "6-223"
Problem is whenever i create a new entity i have to save twice because this wont work:
User newUser = new User();
newUser.setUberField(genUber(user)); // not working!!! no id yet
save(newUser); // not working!!! no id yet
this will work:
User newUser = new User();
save(newUser); // Save 1st
newUser.setUberField(genUber(user));
save(newUser); // save 2nd time
Can i overcome this redundant save?