休眠查询没有给出预期的结果
**我想读取基于那里的名字匹配与传递字符匹配的用户,我为它写了Hibernate Criteria查询,但它不给我输出它返回0行`ProjectionList projection = Projections.projectionList().add(Projections.id ).as(“id”)).add(Projections.property(“firstName”)。as(“firstName”)).add(Projections.property(“lastName”)。as(“lastName”))
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<>?
'anil' like 'a'
是错误的。 如果名称是a%
或%a%
,这取决于您想要的名称:以a开头的名称或包含a的名称。
上一篇: hibernate query not giving the expected result
下一篇: Hibernate Criteria conditions or subqueries on OneToMany property values