• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA LIKE condition

RichardH Marais
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using Java 8 with JPA (and Hibernate 5.2.1)  for my ORM.

I am trying to add a LIKE clause to my criteria, but it is still returning the full result set (no errors) without applying the LIKE filter as I would expect.  Please can someone recomment the best way for me to implement this?


My output is as follows (as you can see there is a LIKE clause, but perhaps the parameters are incorrect):

10:46:11,706 INFO  [stdout] (default task-2) Hibernate:
10:46:11,707 INFO  [stdout] (default task-2)     select
10:46:11,707 INFO  [stdout] (default task-2)         employee0_.id as id1_1_,
10:46:11,707 INFO  [stdout] (default task-2)         employee0_.AVATAR as AVATAR2_1_,
10:46:11,707 INFO  [stdout] (default task-2)         employee0_.AVERAGE_RATING as AVERAGE_3_1_,
10:46:11,707 INFO  [stdout] (default task-2)         employee0_.DISTANCE as DISTANCE4_1_,
10:46:11,707 INFO  [stdout] (default task-2)         employee0_.DRIVERS_LICENCE as DRIVERS_5_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.EMAIL_ADDRESS as EMAIL_AD6_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.FIRST_NAME as FIRST_NA7_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.JOB_DESCRIPTION as JOB_DESC8_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.JOB_DETAILS as JOB_DETA9_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.JOB_TITLE as JOB_TIT10_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.JOINING_DATE as JOINING11_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.LASTACCESS_DATE as LASTACC12_1_,
10:46:11,708 INFO  [stdout] (default task-2)         employee0_.LAST_NAME as LAST_NA13_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.MOBILE_NUMBER as MOBILE_14_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.PASSWORD as PASSWOR15_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.PHONE_NUMBER as PHONE_N16_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.SALARY as SALARY17_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.SALARY_TIMEFRAME as SALARY_18_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.SEX as SEX19_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.USERNAME as USERNAM20_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.WORK_LAT1 as WORK_LA21_1_,
10:46:11,709 INFO  [stdout] (default task-2)         employee0_.WORK_LAT2 as WORK_LA22_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LAT3 as WORK_LA23_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LAT4 as WORK_LA24_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LAT5 as WORK_LA25_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LONG1 as WORK_LO26_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LONG2 as WORK_LO27_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LONG3 as WORK_LO28_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LONG4 as WORK_LO29_1_,
10:46:11,710 INFO  [stdout] (default task-2)         employee0_.WORK_LONG5 as WORK_LO30_1_
10:46:11,711 INFO  [stdout] (default task-2)     from
10:46:11,711 INFO  [stdout] (default task-2)         employee employee0_
10:46:11,711 INFO  [stdout] (default task-2)     where
10:46:11,711 INFO  [stdout] (default task-2)         employee0_.FIRST_NAME like ?
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2785
Android Chrome Eclipse IDE
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried without the Predicate?

RichardH Marais
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits,

thanks for the reply.

Funny thing, I have not changed my code, and it started working.  I think the server was not getting the rebuilt project or something. So the code above works.
Roel De Nijs
Posts: 10763
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RichardH Marais wrote:Funny thing, I have not changed my code, and it started working.

Ah, the automagically self-solving bug/issue! Definitely my favourite kind
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!