Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Using wildcard % in Hibernate (v 3.2.5) with named query

Thread view: 
traneHead - 24 Sep 2007 13:52 GMT
Trying to use a named query put in a hbm like:

<query name="Point.findByTitle">
   from Point point where point.title like :title
   <query-param name="title" type="String" />
 </query>

except I'd like to put wildcards on the named parameter like '%:title
%' but then I get a IAE: "No positional parameters in query"
so I'm guessing that the :title parameter isn't discovered by
hibernate then. I've tried different methods of escaping the % and
other esoteric formatting but no-go...

Any suggestions on how to do this?
Lew - 24 Sep 2007 13:56 GMT
> Trying to use a named query put in a hbm like:
>
>  <query name="Point.findByTitle">
>     from Point point where point.title like :title
>     <query-param name="title" type="String" />
>   </query>

What advantage does aliasing "Point" to "point" confer?

Signature

Lew

traneHead - 24 Sep 2007 14:47 GMT
> > Trying to use a named query put in a hbm like:
>
[quoted text clipped - 7 lines]
> --
> Lew

None in this example.
Why? Does it have anything to do with the wildcard question?
Lew - 24 Sep 2007 14:55 GMT
>>> Trying to use a named query put in a hbm like:
>>>  <query name="Point.findByTitle">
[quoted text clipped - 8 lines]
> None in this example.
> Why? Does it have anything to do with the wildcard question?

Because it caught my eye, and I was curious.  Usually an alias table name is a
shorter version, so the duplication stood out for me.

This is a discussion group.  I was discussing.

Signature

Lew

traneHead - 24 Sep 2007 18:51 GMT
> >>> Trying to use a named query put in a hbm like:
> >>>  <query name="Point.findByTitle">
[quoted text clipped - 16 lines]
> --
> Lew

OK, no the example query might as well (and should) be written 'from
Point where title like :title', the aliasing was a leftover from
copying/pasting/deleting (although not enough of the latter
apparently ;))
Lew - 24 Sep 2007 22:22 GMT
> Trying to use a named query put in a hbm like:
>  <query name="Point.findByTitle">
>     from Point point where point.title like :title
>     <query-param name="title" type="String" />
>   </query>

I reviewed the Java Persistence API today.  Looks to me like :varName is a
syntax for a variable only; there is no concatenation to surrounding tokens.
You will have to include the wildcard ('%') in the substitution value for the
named parameter.

Signature

Lew

traneHead - 25 Sep 2007 22:35 GMT
> > Trying to use a named query put in a hbm like:
> >  <query name="Point.findByTitle">
[quoted text clipped - 9 lines]
> --
> Lew

Thank you. That's the way.
Adam Maass - 27 Sep 2007 04:21 GMT
> Trying to use a named query put in a hbm like:
>
[quoted text clipped - 8 lines]
> hibernate then. I've tried different methods of escaping the % and
> other esoteric formatting but no-go...

try:

from Point where title like concat ('%', :title, '%')


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.