Hibernate: same generated value in two properties
- by Markos Fragkakis
Hi,
I have an entity A with fields:
aId (the system id)
bId
I want the first to be generated:
@Id
@Column(name = "PRODUCT_ID", unique = true, nullable = false, precision = 12, scale = 0)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PROD_GEN")
@BusinessKey
public Long getAId() {
return this.aId;
}
I want the bId to be initially exactly as the aId. One approach is to insert the entity, then get the aId generated by the DB (2nd query) and then update the entity, setting the bId to be equal to aId (3rd query). Is there a way to get the bId to get the same generated value as aId?
Note that afterwards, I want to be able to update bId from my gui.
If the solution is JPA, even better.