[英]How to pre-fill a transient value on a JPA Entity
How to pre-fill a transient attribute (say accountId) on a JPA Entity.如何在 JPA 实体上预填充瞬态属性(比如 accountId)。 I am trying to set accountId using a constant fetched from the application environment (say appAccountId).我正在尝试使用从应用程序环境中获取的常量(比如 appAccountId)来设置 accountId。 Is this the right way to fetch this information, when a select is run on the Entity?当在实体上运行 select 时,这是获取此信息的正确方法吗?
@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
}
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.