How to convert the "detailDate" attribute into Date or LocalDate datatype if the "detailDate" attribute is String datatype in database?

How to convert the “detailDate” attribute into Date or LocalDate datatype if the “detailDate” attribute is String datatype in database? Beacause I want to solve a condition which is display the most updated “Odometer” value based on the “masterList” and “detailDate”. Reminder: This code is in Jmix 2.0. I show a code in java:

" List previousFuelDetails = dataManager.load(FuelDetails2.class)
.query("select e from FuelDetails2 e " +
"where e.masterList = :masterList " +
"and e.detailDate < :detailDate " +
“order by e.detailDate desc, e.time desc”)
.parameter(“masterList”, selectedMasterList)
.parameter(“detailDate”, selectedDetailDate)
.list();

if (!previousFuelDetails.isEmpty()) {
FuelDetails2 lastFuelDetailBeforeSelectedDate = previousFuelDetails.get(0);
lastodometerField.setValue(String.valueOf(lastFuelDetailBeforeSelectedDate.getOdometer()));
} else {
// Handle the case where no data exists for the selected date or previous dates
lastodometerField.setValue(“0”);
} "

I also use “Cast” to convert it into Datedatatype but it gives an error. Such this:

    "List<FuelDetails2> fuelDetailsList = dataManager.load(FuelDetails2.class)
            .query("select e from FuelDetails2 e " +
                "where e.driverId = :driver " +
                "and e.masterList = :masterList " +
                "and (CAST(e.detailDate AS date) < :selectedDate or (CAST(e.detailDate AS date) = :selectedDate and e.time <= :selectedTime))")
            .parameter("driver", selectedDriver)
            .parameter("masterList", selectedMasterList)
            .parameter("selectedDate", selectedDate, TemporalType.DATE) // Use TemporalType.DATE for date-only values
            .parameter("selectedTime", selectedTime)
            .list();"

Hi!

It’s not entirely clear what exactly error you’re getting.
Can you please provide a small test project that reproduces the problem.

Regards,
Dmitriy

This is the error “io.jmix.data.impl.jpql.JpqlSyntaxException: Errors found for input jpql:[select e from FuelDetails2 e where e.masterList = :masterList and cast(e.detailDate as datetime) < :target and e.time <= :time order by e.time desc]
CommonErrorNode [<unexpected: [@23,71:71=‘e’,<61>,1:71], resync=cast(e.detailDate as datetime) < :target>]”.