Reputation: 6110
How to pre-fill a transient attribute (say accountId) on a JPA Entity. I am trying to set accountId using a constant fetched from the application environment (say appAccountId). Is this the right way to fetch this information, when a select is run on the Entity?
@Entity
public class Foo {
@Value("${app.account.id}")
private String appAccountId;
private String transient accountId;
@Postload
public void postLoad() {
accountId = appAccountId;
}
}
Upvotes: 0
Views: 242
Reputation: 2255
Just add this value as a constructor parameter.
public class Foo {
public Foo(@Value("${app.account.id}") String accountId) {
this.accountId = accountId
}
....
Upvotes: 1