以下の内容はhttps://uga-box.hatenablog.com/entry/2020/10/16/000000より取得しました。


【Doma】PostgresのJSON型を利用する

以前、Domaを使ってSpring Boot アプリケーションからPostgresに接続した

uga-box.hatenablog.com

これに追加で、JSON型のカラムを用意したい

## Entity Entityにプロパティを追加する

方はStringで定義する

  @Id
  @Column(name = "search_condition")
  String searchCondition;

アプリケーション

アプリケーション側では、Jacksonを使ってJSON文字列に変換したものをEntityにセットする

PropertyMapping propertyMapping = new PropertyMapping();
ObjectMapper mapper = new ObjectMapper();
String condition = mapper.writeValueAsString(searchCondition);
propertyMapping.setSearchCondition(condition);

SQL

最後にINSERTするsqlファイルでは例えば次のように::jsonbをつけて定義する

/*update.searchCondition*/'search_condition'::jsonb



以上の内容はhttps://uga-box.hatenablog.com/entry/2020/10/16/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14