Some preconditions:
I am not using Oracle DB sequence generator. Instead of it, I rely on the Hibernate sequence generator e.x.
@Entity
@Table(name = "JPA_ENTITY_A")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
public class JpaEntityA{
@Id
@Type(type = "uuid-binary")
@GeneratedValue(generator = "system-uuid")
private UUID id;
@Column(name="NAME_WITH_ID")
String nameWithGeneratedId;
}
What I want is to persist the following generated value into the column "NAME_WITH_ID": this.nameWithGeneratedId+this.id
Is it feasible to do the following:
public String getNameWithGeneratedId(){
return this.nameWithGeneratedId+this.id;//hope that the returned value will be persisted
}
Or is it possible to retrieve in advance before persisting entity to the DB generated id? If yes, then how can I accomplish it? (based on the comments below it is not possible to do it)
Thx in advance.
You can't; the act of persisting itself is what creates the ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With