Java 未转换查询中使用的方法为的枚举
我使用spring引导和spring数据jpa 我有一个整型数据类型的字段。 我有一个枚举,该字段的值不同Java 未转换查询中使用的方法为的枚举,java,spring-boot,jpa,spring-data-jpa,Java,Spring Boot,Jpa,Spring Data Jpa,我使用spring引导和spring数据jpa 我有一个整型数据类型的字段。 我有一个枚举,该字段的值不同 public class Operation{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "operation_Sequence") @SequenceGenerator(name = "operation_Sequence", sequenceName = "operat
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();
因此,该命令不会被转换
有什么想法吗?您不能在JPQL查询中使用任意Java代码段 但是你可以用。 请注意,您需要使用。因此,以下或类似的方法应能起作用:
@Query(value = "select ce from Operation ce where "
+ "ce.eventProcessStatus
= :#{ T(com.ns.perma.domain.constants.EventProcessStatus).CLOSE.id ")
public List<Operation> findAllOperation();
不能在JPQL查询中使用任意Java代码段 但是你可以用。 请注意,您需要使用。因此,以下或类似的方法应能起作用:
@Query(value = "select ce from Operation ce where "
+ "ce.eventProcessStatus
= :#{ T(com.ns.perma.domain.constants.EventProcessStatus).CLOSE.id ")
public List<Operation> findAllOperation();
@詹绍德是对的。你也可以这样试试 可以使用枚举值作为参数并传入查询
@Query(value = "select ce from Operation ce where ce.eventProcessStatus= ?1")
public List<Operation> findAllOperation(int enumValue);
@詹绍德是对的。你也可以这样试试 可以使用枚举值作为参数并传入查询
@Query(value = "select ce from Operation ce where ce.eventProcessStatus= ?1")
public List<Operation> findAllOperation(int enumValue);
无法通过自定义javax.persistence.AttributeConverter将操作中的eventProcessStatus类型更改为eventProcessStatus,或者,如果您希望javax.persistence.Enumerated是基于序号/字符串的,那么您可以简单地使用它吗?您可以同时添加操作类吗?您的意思是您不能修改类操作吗?如果我使用转换器,查询将需要如何修改?您是否可以通过自定义命令将操作中的eventProcessStatus类型更改为eventProcessStatusjavax.persistence.AttributeConverter,或者如果您喜欢它是基于序号/字符串的,甚至简单地使用javax.persistence.Enumerated?您可以添加操作类吗?您的意思是您不能修改类操作?如果我使用编译但在运行时失败的转换器,编译但在运行时失败,查询需要如何修改