簡體   English   中英

如何在 JPA 實體上預填充瞬態值

[英]How to pre-fill a transient value on a JPA Entity

如何在 JPA 實體上預填充瞬態屬性(比如 accountId)。 我正在嘗試使用從應用程序環境中獲取的常量(比如 appAccountId)來設置 accountId。 當在實體上運行 select 時,這是獲取此信息的正確方法嗎?

@Entity
public class Foo {

  @Value("${app.account.id}")
  private String appAccountId;

  private String transient accountId;

  @Postload 
  public void postLoad() {
      accountId = appAccountId;
  }

}

只需將此值添加為構造函數參數即可。

public class Foo {
    public Foo(@Value("${app.account.id}") String accountId) {
        this.accountId = accountId
    }
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM