0

I am trying to write a Select statement using JPA 2 provided CriteriaQuery for the following scenario:

  1. Group items and if at least one of the columns is 'true', return true
  2. Group items and if all columns are 'true', return true

I noticed there is bool_and and bool_or functions in PostGreSQl. Here is a link that explains these functions. boolean aggregate functions How do I achieve this functionality using JPA CriteriaQuery/CriteriaBuilder?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Yogesh Ghimire
  • 432
  • 1
  • 8
  • 21

2 Answers2

1

You can invoke any native SQL function using

CriteriaBuilder.function('bool_and', Boolean.class, args)

Where "args" are the arguments that your function takes, and the second argument is the return type (see the javadocs). Obviously you then lose database-independence, but then you may not care about such things.

0

JPA doesn't support custom functions. It's achievable with hibernate (look here) or with native query. Both will require significant chanegs to your code.

asm0dey
  • 2,841
  • 2
  • 20
  • 33