• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Why can't I create a custom query for looking up an item by a keyword?

 
Ranch Hand
Posts: 442
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an Entity class for Item, but what I want to do is have it so that people can look up a keyword and find the item instead of having to type the exact name.   For example, if you have popsicle sticks as an item, I want them to be able to just type popsicle and get the item back.  

Here is my repository class.



I'm getting an error that Keyword is not a property of item.  

However, I made another program similar to this, and it worked just fine, so I don't understand the error and how to fix it.

When I change it to findItemByName, it only gives back the results if I type the exact name of the item and ignores the custom query.
 
Nathan Milota
Ranch Hand
Posts: 442
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed it to findItemByNameContaining and got rid of the native query and it seems to work.   I don't know why the native query wasn't working though.
 
Saloon Keeper
Posts: 23409
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you shouldn't use native queries at all unless there's a compelling reason not to use JPQL.

But I suspect that your fault was that you coded "where i.name LIKE %:keyword%" when you should have coded "where i.name LIKE '%:keyword%'". Note the extra quotes because this is now a string expression and not a direct variable reference.

Although if I remember correctly. there are some problems with that sort of syntax, so I'm glad you found a solution.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic