Thanks for the suggestion havent tried this yet, but it looks with JPA 2.1 Converter it actually works. Tested on Postgres 9.5.4.2, MySQL 5.1 and Oracle 12.2 and it works. Anyway it works like this: The filter:
@FilterDef(name = AbstractActivatableEntityDefinition.ACTIVATABLE_FILTER)
@Filter(name = AbstractActivatableEntityDefinition.ACTIVATABLE_FILTER, condition = "(({alias}.active = 1) OR (CURRENT_TIMESTAMP BETWEEN {alias}.active_from AND {alias}.active_to))", deduceAliasInjectionPoints = false)
The column:
@Column(name = "active")
@Convert(converter = IntegerToBooleanConverter.class)
boolean isActive();
And the converter looks like this:
public class IntegerToBooleanConverter implements AttributeConverter<Boolean, Integer> {
@Override public Integer convertToDatabaseColumn(Boolean attribute) {
return attribute ? 1 : 0;
}
@Override public Boolean convertToEntityAttribute(Integer dbData) {
return !(dbData == null || dbData == 0);
}
}
|