Skip to content

Instantly share code, notes, and snippets.

@dotJoel
Last active March 7, 2024 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotJoel/f7d8445b538bf1a2bec3556f3f4f8d97 to your computer and use it in GitHub Desktop.
Save dotJoel/f7d8445b538bf1a2bec3556f3f4f8d97 to your computer and use it in GitHub Desktop.
Using JPA, here is how I created a predicate that searches a JSONB column for any of the provided keys.
builder.equal(
builder.function(
"JSONB_EXISTS_ANY",
Boolean.class,
root.get("nameOfJsonbColumnToSearch"),
builder.function(
"string_to_array",
String.class,
builder.literal(String.join(",", setOfValuesToSearchFor)),
builder.literal(",")
)
),
true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment