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;
}
}
Just add this value as a constructor parameter.
public class Foo {
public Foo(@Value("${app.account.id}") String accountId) {
this.accountId = accountId
}
....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.