1

I have an entity defined as this:

public class Alert extends {
    @Column(name = "STATUS_CDE", nullable = false, length = 1)
    @Convert(converter = AlertStatusCodeTypeConverter.class)
    private AlertStatusCodeType statusCde;
}

statusCde is an enum field.

public enum AlertStatusCodeType {

    INACTIVE("I"),

    ACTIVE("A")

    private String code;

    AlertStatusCodeType(String c) {
        this.code = c;
    }
}

When save into and read from db, the converter converts from 1 char String to enum.

@Converter(autoApply = true)
public class AlertStatusCodeTypeConverter implements AttributeConverter<AlertStatusCodeType, String> {

    // take the enum and convert to the value to be inserted into the database
    @Override
    public String convertToDatabaseColumn(AlertStatusCodeType alertStatusCodeType) {
    }

    // take the value from the database and convert it to the enum
    @Override
    public AlertStatusCodeType convertToEntityAttribute(String code) {
    }
}

Now I want to write a JPA derived query to select those rows whose id in the list and status is active. I can write this

List<Alert> findAllByIdInAndStatusCde(List<Long> ids, AlertStatusCodeType statusCode);

it works but ideally I don't need to pass in the status because all I need is those with status as 'A', but if I write this, it fails

findAllByIdInAndStatusCdeActive(List<String> numbers)

No property active found for type AlertStatusCodeType! Traversed path: Alert.statusCde., nor can I use like CdeIsActive, from the documentation https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repository-query-keywords seems the only possible isXXX is isTrue so it works only with boolean field, can anyone confirm?

Thanks

rhbc73
  • 739
  • 9
  • 24

0 Answers0