0

I am trying to do the following (cb = CriteriaBuilder):

cb.between(
    cb.currentTimestamp(), 
        kampanjeArtikkelPriser.get(KampanjeArtikkelPris_.overstyrtSalgsprisPeriodeFra), 
        kampanjeArtikkelPriser.get(KampanjeArtikkelPris_.overstyrtSalgsprisPeriodeTil)),

But I get the following syntax error:

  • Bound mismatch: The generic method between(Expression<? extends Y>, Y, Y) of type CriteriaBuilder is not applicable for the arguments (Calendar, Path<Calendar>, Path<Calendar>). The inferred type Path<Calendar> is not a valid substitute for the bounded parameter <Y extends Comparable<? super Y>>
    • Bound mismatch: The generic method between(Expression<? extends Y>, Expression<? extends Y>, Expression<? extends Y>) of type CriteriaBuilder is not applicable for the arguments (Expression<Timestamp>, Path<Calendar>, Path<Calendar>). The inferred type Object&Serializable&Cloneable&Comparable<? extends Object&Serializable&Cloneable&Comparable<?>> is not a valid substitute for the bounded parameter <Y extends Comparable<? super Y>>

Would it be possible to convert Expression<Timestamp> to Expression<Calendar>? I seem a bit stuck since I have not found a way to do this, and as far as I am able to see there are not many other options for me either. Changing the entities java types is not an options since this is a somewhat big system, and I do not know what kind of impact that would have.

Lars Juel Jensen
  • 1,643
  • 1
  • 22
  • 31

1 Answers1

0

It seems like a good option would be to do the following instead:

Calendar now = Calendar.getInstance();
cb.and(
    cb.lessThanOrEqualTo(kampanjeArtikkelPriser.get(KampanjeArtikkelPris_.overstyrtSalgsprisPeriodeFra), now),
    cb.greaterThanOrEqualTo(kampanjeArtikkelPriser.get(KampanjeArtikkelPris_.overstyrtSalgsprisPeriodeTil), now)
)
Lars Juel Jensen
  • 1,643
  • 1
  • 22
  • 31