How to convert a date type to sleep

I have a situation. I have two kinds of dates in mysql database. One is the date, and the other is the date and time. Now, in sleep mode, should I check if one date is longer than the other or not?

criteria.add (Restrictions.lt ("award.deadline", "submission.date_received"));

But different types cause problems with displaying "java.lang.ClassCastException: java.lang.String cannot be attributed to java.util.Date".

Even I tried to parse it with a date parser, but it does not accept a date, since it only accepts a string. So, can you tell me how we can convert one date to another type inside the criteria for sleep mode?

+3
source share
1 answer

The problem is what Restrictions.lt(String propertyName, Object value)is the wrong constraint. You need to . Restrictions.ltProperty(String propertyName, String otherPropertyName)

Explanation:

  • Restrictions.lt(String propertyName, Object value) consists in comparing the properties of an object with a specific value
  • Restrictions.ltProperty(String propertyName, String otherPropertyName) consists in comparing two properties of an entity

If you use Restrictions.lt("Y", "X"), and β€œY” is the name of the date property, then hibernate will try to translate β€œX” to the date (not the column name), and parsing β€œX” to the date is, say, a bit more complicated - therefore the Exception is increased.

+5
source

Source: https://habr.com/ru/post/1778248/


All Articles