Search code examples
javahibernatedatespring-annotations

How Can I convert Date String as format yyyy-MM to Date with hibernate annoation


When I tried to use @DateTimeFormat(patter="yyyy-MM") at top of my attribute,

ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Bad format for DATE '2015-05'

What Can I do to solve this problem?


Solution

  • As I test, format lick "yyyy-MMM", "yyyy-MM-dd" all working. The "yyyy-MM" format is not supported by @DateTimeFormat. Then, for getting around, I need attributeConverter or wave magic in getter and setter