相关疑难解决方法(0)

Hibernate查询示例和预测

简而言之:hibernate不支持投影和查询示例?我发现这篇文章:

代码是这样的:

User usr = new User();
usr.setCity = 'TEST';
getCurrentSession().createCriteria(User.class)
.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("name"), "name")
.add( Projections.property("city"), "city")))
.add( Example.create(usr))
Run Code Online (Sandbox Code Playgroud)

就像另一张海报所说的那样,生成的sql继续有一个where类引用y0_ =?而不是this_.city.

我已经尝试了几种方法,并搜索了问题跟踪器,但没有发现任何相关信息.

我甚至尝试使用Projection别名和变形金刚,但它不起作用:

User usr = new User();
usr.setCity = 'TEST';
getCurrentSession().createCriteria(User.class)
.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("name"), "name")
.add( Projections.property("city"), "city")))
.add( Example.create(usr)).setResultTransformer(Transformers.aliasToBean(User.class));
Run Code Online (Sandbox Code Playgroud)

有没有人用例子进行投影和查询?

java hibernate criteria projection

22
推荐指数
3
解决办法
13万
查看次数

标签 统计

criteria ×1

hibernate ×1

java ×1

projection ×1