The following enum is given from a domain model class:
public enum OperationMode {
BATTERY_CHANGE_MODE,
PBP_MODE
}
I also defined a AttributeConverter to convert between LocalDateTime and TimeStamp
@Converter
public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(LocalDateTime locDateTime) {
return (locDateTime == null ? null : Timestamp.valueOf(locDateTime));
}
@Override
public LocalDateTime convertToEntityAttribute(Timestamp sqlTimestamp) {
return (sqlTimestamp == null ? null : sqlTimestamp.toLocalDateTime());
}
}
In a Entity class I need to define a working mapping for java.utitl.Map as element collection:
@ElementCollection
@MapKeyColumn(name = "time")
@Convert(converter = LocalDateTimeAttributeConverter.class)
// some annotations are missing here...
private Map<LocalDateTime, OperationMode> operationHistory;
What is the recommended method to get this working?