i use the following query in JPQL to query the people whose address column is empty.
List rl =
em.createQuery( "select o from Person as o where
o.address IS NULL" ).setFirstResult(
0).setMaxResults( 50).getResultList();
...
this line of code always return an empty list, obviously the table does has entries that match the condition.
class Person {
Address address;
String name;
... }
class Address {
String name;
... }
anyone knows what's wrong with this jpql statement?
thanks in advance.
As mentioned, address column is empty, then try using IS EMPTY expression instead of IS NULL.
em.createQuery( "SELECT o FROM Person o where (o.address.id IS NULL OR o.address.id = 0").setMaxResults(50).getResultList();
Check constraint according to id's datatype.
Also there is no need to mention setFirstResult(0) as it is not going to skip any results & without it, by default all matching results will be fetched.
Related
i have an object "ResponseSerializablePlus"
the object has a few attributes
private int id;
private String cod_nrbe_en;
private int num_sec_ac
this field can bring null values so i need to capture all the registers about this field, you can have id or another field duplicated more than once.
what i was thinking was building a query
Predicate sqlQuery = Predicates.sql("i dont know what to put here");
Predicate criteriaQuery = Predicates.and(
Predicates.equal("id", id),
Predicates.equal("code", cod_nrbe_en)
Predicates.equal("num", num_sec_ac)
);
you can have just 1 value and other fields are null or another case the thing is i dont know how to query or compare those 3 attributes
¿any hint?
I have a query where I need to retrieve a column which I need only temporarily because I need to pass it in the parameter for a where clause, how can I remove this column and its value from my result set after it served that purpose. Hopefully the code will show what I mean...
def empQuery = "select id, name, address from Employee"
def retObj = [:]
def sql = new Sql(datasource)
retObj = sql.rows(empQuery.toString())
retObj.each {
def addressQuery = "select street from Address where employe_id = ${it['id']}
// at this point I want to remove 'id:n' from the result set hash map aka 'it'
}
Because later on I am displaying that result set on a page for the user, and the ID field is not relevant.
So can you please show the Groovy code to remove a column and its value from the rows data structure returned from sql.rows?
from http://docs.groovy-lang.org/latest/html/api/groovy/sql/GroovyRowResult.html
It looks like you can do something line:
retObj.each { it.remove('id')}
However I haven't tried it....
There is my code. Can someone tell me what is wrong?
for(String motorProposalId : proposalMap.keySet()) {
MotorPolicy mp = policyMap.get(motorProposalId);
String query = "SELECT p From Payment Where p.referenceNo = :motorProposalId"+
" AND commenmanceDate >= :startDate AND commenmanceDate <= :endDate";
Query qu = em.createQuery(query);
qu.setParameter("commenmanceDate", mp.getCommenmanceDate());
qu.setParameter("motorProposalId", motorProposalId);
qu.setParameter("startDate", motorDailyCriteria.getStartDate());
qu.setParameter("endDate", motorDailyCriteria.getEndDate());
Query is syntactically incorrect because there is no named parameter commenmanceDate in query string. If commenmanceDate should be named parameter, then it must be prefixed with ':'.
Also then query likely have some semantic problems, because all values included to date comparisons are already known before executing query.
I am wondering about how to search in J2ME. I have been searching in the internet, so many result show to me, and I see in Java2s.com I got a result use RecordFilter and matches method for search in record store.
But my problem is, when I need to pass 2 or more parameters into it. How can result matches with these parameter?
And how to sort descending or ascending like bubble sort?
Concatenate your searches into a single String variable. Separate each of them with ; for example. In the code of the matches method explode the String to get each search criteria.
To make the filter in effect create an instance of SearchFilter and call the matches method with the concantenated String as its param.
For the sort implement the RecordComparator interface ; implement the compare method to build your sort criteria. Make a google search about j2me+recordcomparator to see examples about how to make sorts.
EDIT :
In the code of the matches method explode the String param obtained from the byte[] param. Treat each String exploded to make the criteria.
As I understand you want to pass two string as a search criteria when you wrote :
SearchFilter search = new SearchFilter(txtSearch.getString(), strType);
So in the constructor there should be two params !!!
When you want to make the matching then call
if searchFilter.matches((search1+";"+sType).getBytes())
Then explode the candidate param into two String when you code the matches method.
When I save my Data in RMS I save it as a String[] like I want to save Name, Age,Salary,EmpID for each employee I save it create an array and convert it to bytes and save it in RMS. When i retrieve it i do the reverse process. Now if i want to get employee with names starting with A and with salary 10000 i use the following filter
class UtilFilter implements RecordFilter{
public UtilFilter(String str_searchText,String str_searchText1)
{
this.str_searchText = str_searchText.toLowerCase();
this.str_searchText1 = str_searchText1.toLowerCase();
}
public boolean matches(byte[] bt_byteData)
{
String str_str = "";
String str_str1 = "";
//here goes code how u get back ur String[] from RMS say u get it in Data
str_str = Data[0].trim();
str_str1 = gd_cd.Data[2].trim();
if(str_searchText != null && str_searchText1 != null && str_str.equals(str_searchText) && str_str1.equals(str_searchText1 ))
{
return true;
}
else
{
return false;
}
}
}
This way i can filter any no of parameters.Hope tht helps! :)
I'm creating an HQL query to filter a grid of data:
string formatString = "Type = {0} AND {1} = '{2}' AND CompletedDate > '{3}'
AND CompletedDate < '{4}' AND UserName LIKE '{5}'";
HqlBindingSource.Where = string.Format(formatString, type, keyId, entityID,
fromDate, toDate, toDate, UserTextBox.Text);
The problem I'm having is the string matching on the UserName field. I'm used to working with SQL and I can't get it to match on a value using = or LIKE. Can anyone point me in the right direction for this?
Thanks
I had "toDate" listed twice, so UserTextBox.Text was never used in the query.