This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

hibernate string search question  RSS feed

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm a Hibernate newbie and I've a simple dumb question: I'm trying to construct a HQL statement for searching a database string field. What I want is kind of like:

select n.id from ContactName as n where n.name like attern%

so if the pattern is 'a', I get all the contacts whose name start with an A, for example. However, I can't seem to get this to work -- what's the correct syntax for this? I also tried to add % in the pattern string directly, but that doesn't work neither.

Thanks a lot!!!
Adrian
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the actual ContactName objects back, try using any of the follwing:



Personally, I prefer the first example.

Also, using 'select n.id' will return a List of Long/Integer (depending on how you defined id) if that's what you were trying to do.
[ March 08, 2007: Message edited by: David Madouros ]
 
ranger
Posts: 17344
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with David. Go with the first example.

Do not ever go with the third example, because it leaves you open for SQL based hacker attacks.

Mark
 
Adrian Pang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!