Hibernate exception "java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String".

Solution Verified - Updated -

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, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content