0

I am using postgresql with jpa in playframework 2.2.

I am trying to use like with in in my JPQL by using similar to something like this thread.

select * from table where lower(value) similar to '%(foo|bar|baz)%';

I have tried similar to and ~* in my JPQL but both dint work.

On using similar to it gives

IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: similar near line 1

Is there any way I can use similar to or ~* like functionality apart from using like in JPQL?

Thanks

Community
  • 1
  • 1
singhakash
  • 7,891
  • 6
  • 31
  • 65
  • 1
    And if you'd have read any JPQL reference you would know that this is not valid JPQL so I don't get the idea of ramming whatever SQL into JPQL. JPQL does have "LIKE"; an internet search would show details – Neil Stockton Mar 24 '15 at 07:25
  • 1
    @NeilStockton: `like` is something completely different than `similar to` or `~*`. –  Mar 24 '15 at 07:30
  • @NeilStockton I know its not valid as of the exception also but I was trying to search some alternative of `similar to`apart from using `like` – singhakash Mar 24 '15 at 07:36
  • @nameless horse, yes I know they are different, but the poiint is there are references to JPQL on the web. And when a query doesn't fit into JPQL you have a "native query" where you can put as much database-specific syntax through as you wish. – Neil Stockton Mar 24 '15 at 07:40

1 Answers1

2

There is regex support in EclipseLink, check release note for 2.4:

But I don't know if hibernate supports it too. Think it's not part of JPA spec.

Tomas Kraus
  • 466
  • 2
  • 6