JPA存储库类中的@Cacheable无法读取枚举的更新值

时间:2016-07-31 08:19:09

标签: java mysql spring jpa

我定义了如下的枚举:

public enum Strategy {         DDD,OLD_RATING     }

我有一个如下所示的mysql表:

@Entity
@Table(name = "DRIVER_STATE_MACHINE")
@Data
public class DriverStateMachine  {
    @Id
    @GenericGenerator(name = "gen", strategy = "increment")
    @GeneratedValue(generator = "gen")
    @Column(name = "STATE_ID", nullable = false)
    private int stateId;   

    @Column(name = "STRATEGY", nullable = false)
    @Enumerated(EnumType.STRING)
    private Strategy strategy;
}

这里还有另一个课程:

public interface DriverStateMachineJpaRepository extends JpaRepository<DriverStateMachine, Integer > {

    @Cacheable("driverStateMachine")
    List<DriverStateMachine> findByStrategyOrderByStateId(Strategy strategy);
}

现在,如果我在策略中将OLD_RATING更改为RATING并调用以下函数:

List<DriverStateMachine> allRules = driverStateMachineJpaRepository.findByStrategyOrderByStateId(Strategy.RATING);

我得到以下异常:

org.springframework.dao.InvalidDataAccessApiUsageException: Unknown name value [OLD_RATING] for enum class [com.olacabs.ims.workflow.dpe.event.Strategy]; nested exception is java.lang.IllegalArgumentException: Unknown name value [OLD_RATING] for enum class [com.olacabs.ims.workflow.dpe.event.Strategy]

看起来由于@Cacheable注释,它仍然在读取枚举的旧值。如何确保JPARepository读取更新的值?

0 个答案:

没有答案