3

How can I use find_in_set in jpa?

I need to achieve like this
SQL - select * from teacher where find_in_set("5", deptIds) and id = 101

where deptIds have comma separated ids (I know it's bad idea but legacy.)

To do so I had been tried using Criteria but not found any Restrictions that can fulfill find_in_set.
Note - need possible solution with Criteria and Restrictions

The Hunter
  • 155
  • 2
  • 8

3 Answers3

0
criteriaBuilder.function("find_in_set", Boolean.class,
        criteriaBuilder.literal(s),
        root.get("field"))
ssehs
  • 31
  • 1
0

Here is an example: find_in_set example

Here is java code snippet.


    list.add(cb.greaterThan(cb.function("FIND_IN_SET", Integer.class,
                                    cb.literal(val.toString()), root.get(attributeName)), 0));
Aborn Jiang
  • 981
  • 10
  • 9
-2
select t from Teacher t where find_in_set("5", t.deptIds) = 0 and t.id = 101
barbsan
  • 3,418
  • 11
  • 21
  • 28
Saxon Gbl
  • 1
  • 1