Hibernate with IN and LIKE clauses together


Lionel Koh

I have the following hibernate code,

session.createQuery("from Car as car where car.keywordName like :keyword").setString("keyword", keyword ).list(); 

It takes a keyword with the following parentheses %keyword% and returns a list of cars that contain that keyword. The keyword for cars is a long string separated by commas, for example, for cars the keyword would be "luxury, roomy, convertible, four-seater" and another statement

session.createQuery("from Car as car where car.carId IN (:idList)").setParameterList( "idList", idList ).list();

Return a list of cars from a list of IDs. I've been trying to combine two clauses like and IN to return a list of cars from a list of keywords, not just one keyword.

It would be greatly appreciated if someone could shed some light on this. cheers!

JB Nizet

You have to dynamically create the query to create something like

select car from Car car 
where car.keywordName like :k1 
or car.keywordName like :k2
or car.keywordName like :k3
...

The best tool to do this is the Criteria API (see the third code snippet for an example of a list of restrictions separated by tokenizers or).

Related


Hibernate with IN and LIKE clauses together

Lionel Koh I have the following hibernate code, session.createQuery("from Car as car where car.keywordName like :keyword").setString("keyword", keyword ).list(); It takes a keyword with the following parentheses %keyword% and returns a list of cars that cont

Chain WITH/CASE clauses together

Brooks I'm trying to set labels for nodes to properly characterize nodes created via a LOAD CSV statement (see an earlier question I ran into during this process: Setting labels based on data in LOAD CSV ). I've been able to set the labels during the creation

Chain WITH/CASE clauses together

Brooks I'm trying to set labels for nodes to properly characterize nodes created via a LOAD CSV statement (see an earlier question I ran into during this process: Setting labels based on data in LOAD CSV ). I've been able to set the labels during the creation

How to use INTO and GROUP BY clauses together

Akshay Wahariya SELECT cast ( SUBSTRING ( CAST ("ProcessingDate" AS text), 5, 2 ) as integer), COUNT(*) INTO resultValue1,resultValue2 FROM "DemoLogs"."Project" WHERE "Addr" = 'Y' AND "ProcessingDate" >= 20160110 GROUP BY 1 ORDER BY 1; In my database

join and where clauses in hibernate

Kanica I am using join and where clauses in hibernate 3, but I am not able to reach a solution. I got the error. Query qry= session.createQuery("SELECT addemployee.eid,addemployee.fname,addemployee.location," + "empdet.jtitle,empdet.leadname FROM addem

Like clauses and prepared statements

Guillaume Beauvois I am trying to make a SQL request with a LIKE clause using prepared statements. Here is the code: using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); string Query = "SELECT TOP

Like clauses and prepared statements

Guillaume Beauvois I am trying to make a SQL request with a LIKE clause using prepared statements. Here is the code: using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); string Query = "SELECT TOP

LIKE clauses on columns and groups

Martin I have a postgresqldatabase and a table "phrase" Each line contains a set of words/word groups separated by ",": id | collection (text) | ---+----------------------------+ 1 | apple tree, large orange | 2 | kiwi, apple tree |

Like clauses and prepared statements

Guillaume Beauvois I am trying to make a SQL request with a LIKE clause using prepared statements. Here is the code: using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); string Query = "SELECT TOP

LIKE clauses on columns and groups

Martin I have a postgresqldatabase and a table "phrase" Each line contains a set of words/word groups separated by ",": id | collection (text) | ---+----------------------------+ 1 | apple tree, large orange | 2 | kiwi, apple tree |

Like clauses and prepared statements

Guillaume Beauvois I am trying to make a SQL request with a LIKE clause using prepared statements. Here is the code: using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); string Query = "SELECT TOP

LIKE clauses on columns and groups

Martin I have a postgresqldatabase and a table "phrase" Each line contains a set of words/word groups separated by ",": id | collection (text) | ---+----------------------------+ 1 | apple tree, large orange | 2 | kiwi, apple tree |

Like clauses and prepared statements

Guillaume Beauvois I am trying to make a SQL request with a LIKE clause using prepared statements. Here is the code: using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); string Query = "SELECT TOP

LIKE clauses on columns and groups

Martin I have a postgresqldatabase and a table "phrase" Each line contains a set of words/word groups separated by ",": id | collection (text) | ---+----------------------------+ 1 | apple tree, large orange | 2 | kiwi, apple tree |

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Multiple LIKE clauses in Laravel Eloquent

Marion Serreno I currently have the following code in my controller: $JobSuggestions = DB::table('jobs') ->orwhere('skillsetNeeded','like','%Accounting%') ->orwhere('skillsetNeeded','like','%Web Design%')->get(); The code above works, but I want to get 'Acco

Special patterns for SQL LIKE clauses

Almelyan A special pattern is needed to find characters that are 13 characters long, e.g. the first of 12 numbers is a number. 119910023525PThere are 2 modes: LIKE '____________P' or LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]P' Need

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Multiple LIKE clauses in Laravel Eloquent

Marion Serreno I currently have the following code in my controller: $JobSuggestions = DB::table('jobs') ->orwhere('skillsetNeeded','like','%Accounting%') ->orwhere('skillsetNeeded','like','%Web Design%')->get(); The code above works, but I want to get 'Acco

Compare LIKE clauses to whole words

iSun Currently, my SQL search query use LIKEclause has %some-word-to-search%wildcards. The problem with using the percent wildcard is that it returns all rows that contain part of my search parameter, eg: If I search for cars, it also shows me cartoons ! Is th

SQL query with two like clauses

Cloro I'm a complete beginner, so I apologize in advance if I'm writing this in an incomprehensible way. I've set up a database and I'm using a UI so that the user can get certain bits of data. Users need to be able to search by first and last name to return a

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Multiple LIKE clauses in Laravel Eloquent

Marion Serreno I currently have the following code in my controller: $JobSuggestions = DB::table('jobs') ->orwhere('skillsetNeeded','like','%Accounting%') ->orwhere('skillsetNeeded','like','%Web Design%')->get(); The code above works, but I want to get 'Acco

Special patterns for SQL LIKE clauses

Almelyan A special pattern is needed to find characters that are 13 characters long, e.g. the first of 12 numbers is a number. 119910023525PThere are 2 modes: LIKE '____________P' or LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]P' Need

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Use less than like clauses

Ruben i have some numbers 12000 13093 14013 14111 15543 16883 17932 18920 19903 20390 These numbers are just an example, I have lots of 14s...lots of 15s...etc. Now in WHEREthe clause of the stored procedure I want to exclude all numbers starting with 15 or l

Multiple LIKE clauses in Laravel Eloquent

Marion Serreno I currently have the following code in my controller: $JobSuggestions = DB::table('jobs') ->orwhere('skillsetNeeded','like','%Accounting%') ->orwhere('skillsetNeeded','like','%Web Design%')->get(); The code above works, but I want to get 'Acco