【发布时间】:2020-07-19 19:33:28
【问题描述】:
我使用带有 spring data jpa 的 spring boot
我有一个整数数据类型的字段。 我有一个该字段具有不同值的枚举
public class Operation{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "operation_Sequence")
@SequenceGenerator(name = "operation_Sequence", sequenceName = "operation_Sequence", allocationSize = 1)
private Long id;
private Integer eventProcessStatus;
}
public enum EventProcessStatus {
CLOSE(2),
OPEN(99);
private final int id;
EventProcessStatus(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
在我的存储库中,我搜索将此枚举与 getId 方法一起使用
@Query(value = "select ce from Operation ce where "
+ "(ce.eventProcessStatus=com.ns.perma.domain.constants.EventProcessStatus.CLOSE.getId() )")
public List<Operation> findAllOperation();
执行此查询时,我得到 CLOSE: INVALID IDENTIFIER。
在我看到的sql日志中
...
where
operation0_.event_process_status=com.ns.perma.billing.domain.constants.EventProcessStatus.SUCCESS.getId()
所以命令没有被转换。
有什么想法吗?
【问题讨论】:
-
难道你不能通过自定义
javax.persistence.AttributeConverter将Operation中的eventProcessStatus类型更改为EventProcessStatus,如果你愿意的话,甚至可以简单地使用javax.persistence.Enumerated基于序数/字符串? -
你也可以添加Operation类吗?
-
你的意思是不能修改类
Operation? -
如果我使用转换器,需要如何修改查询
标签: java spring-boot jpa spring-data-jpa