- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
public class ProductDTO {
public ProductDTO(final String name, final Boolean isBrandNew) { ... }
}
QProduct product = QProduct.product
Expression<Boolean> isBrandNew = new CaseBuilder()
.when(product.creaDate.eq(product.modDate)).then(Boolean.TRUE)
.otherwise(Boolean.FALSE)
.as("brandNewProduct")
JPAQuery query = new JPAQuery (this.em);
query.from(product)
.where(product.name.eq("blah"))
.listDistinct(ConstructorExpression.create(ProductDTO
, product.name
, isBrandNew))
在我的查询的最终选择语句中包含“brandNewProduct”列的 CaseBuilder 的正确设置是什么?
现在,我从 hibernate 中得到的只是以下异常
org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to
org.hibernate.hql.internal.ast.tree.SelectExpression
org.hibernate.hql.internal.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:43)
最佳答案
供将来引用...
已经有人发过类似问题here和 here .根据 Timo 的说法,存在一个错误,或者说是 hibernate 强加的限制:
Best Answer Answered by Timo Westkämper on 2013-02-22T01:55:04-05:00 It is syntactically possible, but currently unsupported by Hibernate. Here is a related ticket https://github.com/mysema/querydsl/issues/185
因此,nithril 发布的解决方案实际上对我有用:
query().from(cat).list(cat.name.when("Bob").then(Expressions.numberTemplate(Long, "1")).otherwise(Expressions.numberTemplate(Long, "2")));
我最终使用了:
JPAQuery query = new JPAQuery (this.em);
query.from(product)
.where(product.name.eq("blah"))
.listDistinct(ConstructorExpression.create(ProductDTO
, product.name
, product.modDate.when(product.creaDate)
.then(Expressions.booleanTemplate("true"))
.otherwise(Expressions.booleanTemplate("false"))
))
希望这对其他人有同样问题的情况有所帮助。
关于java - QueryDSL:QueryDSL 2.9.0 中 ConstructorExpression 和 CaseBuilder 的 JPA 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21880923/
我在使用 CASE WHEN THEN 和 EnumPath 时遇到问题 Expression cases = new CaseBuilder().when(qCampaign.campaignSta
public class ProductDTO { public ProductDTO(final String name, final Boolean isBrandNew) { ... }
我是一名优秀的程序员,十分优秀!