Hibernate查询获取0记录,而同一查询从数据库中获取记录

时间:2017-10-23 16:38:36

标签: hibernate

@Repository
public class LoginDao {
    @Autowired
    private SessionFactory factory;

    private Session hbsession;

    @Transactional
    public UserRegistration findCustomer(String email)
    {
        System.out.println("in dao");       
        hbsession = factory.getCurrentSession();
        Query qry = hbsession.createQuery("from UserRegistration where EmailId = '"+email+"'");*emphasized text*
        List<String> list = qry.list();
        System.out.println("list size : "+list.size());
        return (UserRegistration) list;
    }
}

output : query==>QueryImpl(from UserRegistration where EmailId = 'sonam@gmail.com')
Hibernate: select userregist0_.CUSTOMERID as CUSTOMERID1_0_, userregist0_.ADDRESS as ADDRESS2_0_, userregist0_.NUM_CART as NUM_CART3_0_, userregist0_.STR_EMAILID as STR_EMAILID4_0_, userregist0_.STR_FIRST_NAME as STR_FIRST_NAME5_0_, userregist0_.STR_LAST_NAME as STR_LAST_NAME6_0_, userregist0_.STR_MIDDLE_NAME as STR_MIDDLE_NAME7_0_, userregist0_.MOBILE as MOBILE8_0_, userregist0_.PASSWORD as PASSWORD9_0_, userregist0_.STR_USER_ID as STR_USER_ID10_0_, userregist0_.STR_USER_TYPE as STR_USER_TYPE11_0_ from SHOP_USER_REGISTRATION userregist0_ where userregist0_.STR_EMAILID='sonam@gmail.com'
list size : 0

0 个答案:

没有答案