Hibernate exception "java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String".
Issue
- Hibernate exception "java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String":
Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
at org.hibernate.validator.NotEmptyValidator.isValid(NotEmptyValidator.java:36)
at org.hibernate.validator.ClassValidator.getPotentialInvalidValues(ClassValidator.java:524)
at org.richfaces.validator.HibernateValidator.validateClass(HibernateValidator.java:96)
at org.richfaces.validator.HibernateValidator.validateBean(HibernateValidator.java:162)
at org.richfaces.validator.HibernateValidator.validate(HibernateValidator.java:137)
...
Environment
- JBoss Enterprise Application Platform 5.1.0 (EAP).
Resolution
This exception occurs because @NotEmpty hibernate annotation is attached to entity attribute of type Date. The annotation @NotEmpty contains @Size(min = 1) and @Sizs supports only String, Collection, Map and Array. You may consider changing @NotEmpty to @NotNull for Date objects.
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
