I have below table temp_tbl (postgres):
ID(int) NAME(TEXT) LINKS(jsonb)
-------- ---------- -------------------
1 Name1 ["1","23","3", "32]
2 Name2 ["11","3","31", "2]
3 Name3 ["21","13","3", "12]
Now my native query to get rows which has 'LINKS' with value as "3" is:
select * from temp_tbl where links @> '["3"]'
returns rows 2 & 3.
I want implement this query using org.springframework.data.jpa.domain.Specification
I have implemented something like below where the jsonb column is not-an-array, but has key-value json using jsonb_extract_path_text. But the above column stores only values in an array.
My entity class.
@Entity
@Table(name = "temp_tbl")
public class TempTbl {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "LINKS", columnDefinition = "jsonb null")
@Convert(converter = JsonbConverter.class)
private List<String> linkIds;
}
I need help in translating above query into specification using criteriabuilder.