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?
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?
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
Maybe you could use a more appropriate Java type,
like org.joda.time.YearMonth (Joda Time 2.0) or java.time.YearMonth (Java 8).
For example, YearMonth.now()
gives "2015-09".
Then you would need a converter from String to YearMonth.
With Hibernate you can use on your entity :
@org.hibernate.annotations.Type(type = "MyConverter")
private YearMonth yearMonth;
With JPA 2.1 :
@javax.persistence.Convert(converter = MyConverter.class)
private YearMonth yearMonth;