В спячки 4 я мог сделать, какСравнение дат с CriteriaQuery в спящий режим 5
Criteria criteria = session.createCriteria(FlightData.class);
// Restriction to match Departure Location, Arrival Location and ValidTill Date
criteria.add(Restrictions.and(Restrictions.eq("departureLocation", query.getDepartLoc()),
Restrictions.eq("arrivalLocation", query.getArrivalLoc()),
Restrictions.ge("validTill", query.getTravelDate())));
где validTill имеет тип LocalDate в Java 8. Но спящий режим 5, если я люблю
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<FlightData> cq = builder.createQuery(FlightData.class);
Root<FlightData> root = cq.from(FlightData.class);
cq.select(root).where(builder.and(
builder.equal(root.get("departureLocation"), query.getDepartLoc()),
builder.equal(root.get("arrivalLocation"), query.getArrivalLoc()),
builder.ge(root.get("validTill"), query.getTravelDate())
));
то я получаю сообщение об ошибке в методе builder.ge(): Тип CriteriaBuilder не применим для аргументов (Path, LocalDate).
мой FlightData implimentation является
public class FlightData implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 6511441862178750017L;
/** The id serves as a primary key for the table */
private long id;
/** The flight number. */
private String flightNumber;
/** The departure location. */
private String departureLocation;
/** The arrival location. */
private String arrivalLocation;
/** The fare. */
private double fare;
/** The seat availability. */
private String seatAvailability;
/** The flight time. */
private String flightTime;
/** The flight duration. */
private String flightDuration;
/** The flight class. */
private String flightClass;
/** The Valid date. */
private LocalDate validTill;
/**
* Gets the id.
*
* @return the id
*/
public long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(long id) {
this.id = id;
}
/**
* Sets the flight number.
*
* @param flightNum the new flight number
*/
public void setFlightNumber(String flightNum) {
flightNumber = flightNum;
}
/**
* Gets the flight number.
*
* @return the flight number
*/
public String getFlightNumber() {
return flightNumber;
}
/**
* Sets the departure location.
*
* @param depLoc the new departure location
*/
public void setDepartureLocation(String depLoc) {
departureLocation = depLoc;
}
/**
* Gets the departure location.
*
* @return the departure location
*/
public String getDepartureLocation() {
return departureLocation;
}
/**
* Sets the arrival location.
*
* @param arrLoc the new arrival location
*/
public void setArrivalLocation(String arrLoc) {
arrivalLocation = arrLoc;
}
/**
* Gets the arrival location.
*
* @return the arrival location
*/
public String getArrivalLocation() {
return arrivalLocation;
}
/**
* Sets the seat availability.
*
* @param seatAvail the new seat availability
*/
public void setSeatAvailability(String seatAvail) {
seatAvailability = seatAvail;
}
/**
* Gets the seat availability.
*
* @return the seat availability
*/
public String getSeatAvailability() {
return seatAvailability;
}
/**
* Sets the fare.
*
* @param fare the new fare
*/
public void setFare(double fare) {
this.fare = fare;
}
/**
* Gets the fare.
*
* @return the fare
*/
public double getFare() {
return fare;
}
/**
* Sets the local date.
*
* @param date the new local date
*/
public void setValidTillDate(String date) {
StringTokenizer st = new StringTokenizer(date, "-");
int day = Integer.parseInt(st.nextToken());
int month = Integer.parseInt(st.nextToken());
int year = Integer.parseInt(st.nextToken());
validTill = LocalDate.of(year, month, day);
}
/**
* Gets the local date.
*
* @return the local date
*/
public LocalDate getValidTillDate() {
return validTill;
}
/**
* Sets the flight duration.
*
* @param flightDur the new flight duration
*/
public void setFlightDuration(String flightDur) {
flightDuration = flightDur;
}
/**
* Gets the flight duration.
*
* @return the flight duration
*/
public String getFlightDuration() {
return flightDuration;
}
/**
* Sets the flight class.
*
* @param flightClass the new flight class
*/
public void setFlightClass(String flightClass) {
this.flightClass = flightClass;
}
/**
* Gets the flight class.
*
* @return the flight class
*/
public String getFlightClass() {
return flightClass;
}
/**
* Sets the flight time.
*
* @param flighttime the new flight time
*/
public void setFlightTime(String flighttime) {
flightTime = flighttime;
}
/**
* Gets the flight time.
*
* @return the flight time
*/
public String getFlightTime() {
return flightTime;
}
}
Любые предложения о том, как сравнить LocalDate с Hibernate 5 с использованием критериев.
Какая ошибка? также добавьте объект FlightData impl –