Please I have this error
"org.hibernate.NonUniqueResultException: query did not return a unique result: 2"
It works perfectly when I have one result and I need to show the two(or more) results found but I don't know how!
Here is my code:
public class ContactImplDataBase implements ContactDAO {
//.......
...
public Contact getContactByType(String type) {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Criteria criteria = session.createCriteria(Contact.class)
.add(Restrictions.like("type", type));
tx.commit();
return (Contact)criteria.uniqueResult();}
}
And:
public class ContactImpl implements ContactDAO {
//...
..
@Override
public Contact getContactByType(String type) {
Contact contact=null;
for(Contact c:contacts){
if(c.getType().equals(type)){
contact=c;
break;
}
}
return contact;
}
...}
And in the controller:
@RequestMapping(value="/rechercheContact")
public String rechercheContact(Model model, @RequestParam(value="type") String type){
List<Contact> liste=new ArrayList<Contact>();
liste.add(services.getContactByType(type));
model.addAttribute("listeContact", liste);
model.addAttribute("type", type);
return "ex";
}
Any help ?!!