import javax.persistence.AttributeConverter;
public class TaskConverter implements AttributeConverter<TaskType, String> {
@Override
public String convertToDatabaseColumn(TaskType attribute) {
if (attribute instanceof TaskType1) {
return "TASK1";
} else if (attribute instanceof TaskType2) {
return "TASK2";
} else if (attribute instanceof TaskType3) {
return "TASK3";
}
return null;
}
@Override
public TaskType convertToEntityAttribute(String dbData) {
if ("TASK1".equals(dbData)) {
return new TaskType1();
} else if ("TASK2".equals(dbData)) {
return new TaskType1();
} else if ("TASK3".equals(dbData)) {
return new TaskType3();
}
return null;
}
}