In my mysql database I have a table,named:-file_upload table structure is ;-
I have stored picture in this table..Now I want to fetch the image.. So,I have:--
@Table(name = "file_upload")
public class ProfilePic {
private long id;
private String fileName;
private byte[] data;
--setters and getters with @Column annotation---
public ProfilePic(BigInteger userId) {
super();
this.userId = userId;
}
}
my dao class is:--
public ProfilePic FetchImage(ProfilePic profilePic) {
String hql = "select data from ProfilePic where userId = :userId1 ";
logger.info( profilePic.getUserId());
Query query = (Query) sessionFactory.getCurrentSession().createQuery(hql)
.setParameter("userId1", profilePic.getUserId());
return (ProfilePic) query.uniqueResult();
}
But I am getting error:---
org.hibernate.NonUniqueResultException: query did not return a unique result: 4
why??where is the problem??