• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 447
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: 447
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: 24283
167
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.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic