Hibernate: same generated value in two properties
Posted
by Markos Fragkakis
on Stack Overflow
See other posts from Stack Overflow
or by Markos Fragkakis
Published on 2010-05-05T13:29:12Z
Indexed on
2010/05/05
13:38 UTC
Read the original article
Hit count: 260
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.
© Stack Overflow or respective owner