Hibernate using Criteria ... Expression.in error .....

L

LuckyBoy

i have the following entries in Database table
mysql> select email, firstname, lastname from contact;
+-----------------+-----------+----------+
| email | firstname | lastname |
+-----------------+-----------+----------+
| (e-mail address removed) | rahul | saini |
| (e-mail address removed) | rohit | saini |
+-----------------+-----------+----------+

Through front end I am getting both the above email ids (as search
text "(e-mail address removed), (e-mail address removed)" )
and I have to display firstname and lastname for these.
My Hibernate 3 code to search (using Hibernate Criteria and
Expression.in() and display this is as below:
=============================================
// get search string as req parameter, tokenize it by ,
// create a simple String[] contactsArr and assign these email
ids to its elements
String sContacts = req.getParameter("SearchString").trim();
StringTokenizer emailsTok = new StringTokenizer(sContacts, ",");
int totalTokens = emailsTok.countTokens();
String[] contactsArr = new String[totalTokens];
int i = 0;
while(emailsTok.hasMoreTokens()){
contactsArr = emailsTok.nextToken().trim();
i++;
}
if(sContacts != null){
List result = null;
try{
Session sess = UtilHelper.getSessionFactory().openSession();
Transaction newTrans = sess.beginTransaction();
Criteria crit = sess.createCriteria(Contact.class);
result = crit.add(Expression.in("Email", contactsArr)).list();
if(result != null){
Iterator iter = result.iterator();
while(iter.hasNext()){
Contact contact = (Contact)iter.next();
pw.println(contact.getFirstName() + "," + contact.getLastName());
}
}
newTrans.commit();
sess.close();
}
==============================================
However, instead of printing
rahul,saini
rohit,saini

it is printing
rahul,saini
rahul,saini
==============================================
HQL generated is :
Hibernate: select this_.ID as ID0_0_, this_.FIRSTNAME as
FIRSTNAME0_0_, this_.LA
STNAME as LASTNAME0_0_, this_.EMAIL as EMAIL0_0_, this_.DOB as
DOB0_0_, this_.PH
_LANDLINE as PH6_0_0_, this_.PH_MOBILE as PH7_0_0_, this_.CA_STREET as
CA8_0_0_,
this_.CA_CITY as CA9_0_0_, this_.CA_COUNTRY as CA10_0_0_,
this_.CA_PINCODE as C
A11_0_0_, this_.PA_STREET as PA12_0_0_, this_.PA_CITY as PA13_0_0_,
this_.PA_COU
NTRY as PA14_0_0_, this_.PA_PINCODE as PA15_0_0_ from CONTACT this_
where this_.
EMAIL in (?, ?)

Where is it wrong ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top