作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 CASE WHEN THEN
和 EnumPath
时遇到问题
Expression<CampaignStatus> cases = new CaseBuilder().when(qCampaign.campaignStatus.gt(CampaignStatus.NOT_SENT)).then(CampaignStatus.ERROR);
(CampaignStatus 是枚举)
我想最终在请求更新中使用这个案例
EnumExpression<CampaignStatus> cases = new CaseBuilder().when(qCampaign.campaignStatus.eq(CampaignStatus.SENT)).then(CampaignStatus.ERROR).otherwise(CampaignStatus.ERROR);
new JPAUpdateClause(manager, qCampaign)
.set(qCampaign.campaignStatus, cases)
.where(qCampaign.id.eq(campaignId))
.execute();
Q类:
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QCampaign extends EntityPathBase<Campaign> {
private static final long serialVersionUID = -1869070992L;
private static final PathInits INITS = PathInits.DIRECT2;
public static final QCampaign campaign = new QCampaign("campaign");
public final StringPath address = createString("address");
public final StringPath application = createString("application");
public final StringPath applicationId = createString("applicationId");
public final SetPath<CampaignFleet, QCampaignFleet> campaignFleet = this.<CampaignFleet, QCampaignFleet>createSet("campaignFleet", CampaignFleet.class, QCampaignFleet.class, PathInits.DIRECT2);
public final EnumPath<net.atos.tum.rcs.rmessage.core.enums.CampaignStatus> campaignStatus = createEnum("campaignStatus", net.atos.tum.rcs.rmessage.core.enums.CampaignStatus.class);
public final SetPath<CampaignVehicle, QCampaignVehicle> campaignVehicle = this.<CampaignVehicle, QCampaignVehicle>createSet("campaignVehicle", CampaignVehicle.class, QCampaignVehicle.class, PathInits.DIRECT2);
public final DateTimePath<java.util.Date> createDate = createDateTime("createDate", java.util.Date.class);
public final QDisplayMethod displayMethod;
public final StringPath gpsCoords = createString("gpsCoords");
public final BooleanPath html = createBoolean("html");
public final NumberPath<Long> id = createNumber("id", Long.class);
public final StringPath phoneNumber = createString("phoneNumber");
public final BooleanPath pro = createBoolean("pro");
public final StringPath progress = createString("progress");
public final SetPath<PushConfig, QPushConfig> pushConfigs = this.<PushConfig, QPushConfig>createSet("pushConfigs", PushConfig.class, QPushConfig.class, PathInits.DIRECT2);
public final DateTimePath<java.util.Date> sendingDate = createDateTime("sendingDate", java.util.Date.class);
public final SetPath<TemplateMessage, QTemplateMessage> templateMessages = this.<TemplateMessage, QTemplateMessage>createSet("templateMessages", TemplateMessage.class, QTemplateMessage.class, PathInits.DIRECT2);
public final BooleanPath temporary = createBoolean("temporary");
public final StringPath title = createString("title");
public final QUser user;
public QCampaign(String variable) {
this(Campaign.class, forVariable(variable), INITS);
}
public QCampaign(Path<? extends Campaign> path) {
this(path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
}
public QCampaign(PathMetadata<?> metadata) {
this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT);
}
public QCampaign(PathMetadata<?> metadata, PathInits inits) {
this(Campaign.class, metadata, inits);
}
public QCampaign(Class<? extends Campaign> type, PathMetadata<?> metadata, PathInits inits) {
super(type, metadata, inits);
this.displayMethod = inits.isInitialized("displayMethod") ? new QDisplayMethod(forProperty("displayMethod")) : null;
this.user = inits.isInitialized("user") ? new QUser(forProperty("user"), inits.get("user")) : null;
}
}
异常(exception):
10:41:50.436 [qtp1497627503-24] ERROR [] NewCampaign Render queue error in SetupRender[NewCampaign]: org.hibernate.hql.internal.ast.tree.JavaConstantNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression
org.apache.tapestry5.ioc.internal.util.TapestryException: org.hibernate.hql.internal.ast.tree.JavaConstantNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:158) ~[tapestry-core-5.3.7.jar:?]
at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.render(ComponentPageElementImpl.java:186) ~[tapestry-core-5.3.7.jar:?]
at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72) [tapestry-core-5.3.7.jar:?]
at org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124) [tapestry-core-5.3.7.jar:?]
at $PageRenderQueue_53dac9603a07.render(Unknown Source) [?:?]
at $PageRenderQueue_53dac96039e5.render(Unknown Source) [?:?]
at org.apache.tapestry5.internal.services.MarkupRendererTerminator.renderMarkup(MarkupRendererTerminator.java:37) [tapestry-core-5.3.7.jar:?]
at org.got5.tapestry5.jquery.services.js.JSModule$1.renderMarkup(JSModule.java:44) [tapestry5-jquery-3.4.0.jar:?]
最佳答案
我找到了一个解决方案:
EnumExpression<CampaignVehicleStatusEnum> cases = new CaseBuilder()
.when(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.TO_SAVE))
.then(EnumTemplate.create(CampaignVehicleStatusEnum.class, String.valueOf(CampaignVehicleStatusEnum.OK.getStatus())))
.otherwise(EnumTemplate.create(CampaignVehicleStatusEnum.class, String.valueOf(CampaignVehicleStatusEnum.ERROR.getStatus())));
请求更新:
new JPAUpdateClause(manager, qCampaignVehicle)
.set(qCampaignVehicle.status, cases)
.where(qCampaignVehicle.pk.campaign.id.eq(campaignId))
.where(qCampaignVehicle.pk.vehicle.id.in(listOfVehicleId))
.where(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.TO_SAVE)
.or(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.ERROR_TO_SAVE)))
.execute();
关于mysql - 带 CaseBuilder 的 EnumPath(QueryDSL 3.6.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32737068/
我在使用 CASE WHEN THEN 和 EnumPath 时遇到问题 Expression cases = new CaseBuilder().when(qCampaign.campaignSta
public class ProductDTO { public ProductDTO(final String name, final Boolean isBrandNew) { ... }
我是一名优秀的程序员,十分优秀!