hibernate查询没有给出预期的结果

时间:2015-05-01 11:47:06

标签: sql hibernate

**我想根据那里的第一个名称匹配读取用户我写的Hibernate Criteria查询相同但是它没有给我输出它返回0行`ProjectionList projections = Projections.projectionList()                                 。新增(Projections.id()作为(" ID&#34))     。新增(Projections.property("的firstName"。),为("的firstName&#34)) 。新增(Projections.property(" lastName的"。),为(" lastName的&#34))

                      long a=4;
                        Criteria cr = session.createCriteria(UserInfo.class)
                        .createAlias("blist", "embeddedObj") 
                        .add(Restrictions.ilike("firstName",name))
                        .add(Restrictions.ne("embeddedObj.userid",a))
                        .setProjection(projections)
                        .setResultTransformer(new AliasToBeanNestedResultTransformer(UserInfo.class));
                      userInfos =(List<UserInfo>)cr.list();` **

这是由hibernate为同一个

生成的sql查询
select this_.id as y0_, this_.firstName as y1_, this_.lastName as y2_,  from Users this_ inner join USER_BLOCKUSERS embeddedob1_ on this_.id=embeddedob1_.USER_ID where lower(this_.firstName) like ? and![this is the user table![\]\[1\]][1] embeddedob1_.userid<>?

1 个答案:

答案 0 :(得分:1)

'anil' like 'a' 

是假的。如果名称为a%%a%,则会出现这种情况,具体取决于您的需求:以a开头的名称或包含。的名称。