What would cause an Hibernate InvalidStateException

Sam picture Sam · Nov 1, 2010 · Viewed 10.5k times · Source

I get this error, even though there are no validation constraints in my model class (all of the member variables are set properly but I stil get this exception on object creation). How do I debug this error?

javax.el.ELException: org.hibernate.validator.InvalidStateException: valida
tion failed for: com.mycompany.model.User
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.jav
a:339)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.jav
a:280)
        at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.jav
a:59)
        at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:
65)
        at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
        at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.ja
va:276)
        at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
        at org.jboss.seam.navigation.Pages.callAction(Pages.java:703)
        at org.jboss.seam.navigation.Pages.preRender(Pages.java:331)
        at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseList
ener.java:561)
        at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPh
aseListener.java:472)
        at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhas
eListener.java:148)
        at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListen
er.java:118)
        at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:214)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:96)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:
139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applica
tionFilterChain.java:206)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:83)
        at org.jboss.seam.web.RewriteFilter.doFilter(RewriteFilter.java:63)

        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:4
0)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java
:90)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java
:64)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:4
5)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEnc
odingFilter.java:42)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java
:206)
        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290
)
        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(Ba
seFilter.java:388)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
        at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:5
6)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)

        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamF
ilter.java:69)
        at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applica
tionFilterChain.java:206)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHea
derFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applica
tionFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWra
pperValve.java:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardCon
textValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Se
curityAssociationValve.java:190)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authe
nticatorBase.java:433)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContex
tValve.java:92)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.
process(SecurityContextEstablishmentValve.java:126)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.
invoke(SecurityContextEstablishmentValve.java:70)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostVa
lve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportVa
lve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(Ca
chedConnectionValve.java:158)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngi
neValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapte
r.java:330)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor
.java:829)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.
process(Http11Protocol.java:598)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.ja
va:447)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.validator.InvalidStateException: validation failed
 for: com.mycompany.model.User            at org.hibernate.validator.event.ValidateEventListener.validate(Val
idateEventListener.java:148)
        at org.hibernate.validator.event.ValidateEventListener.onPreInsert(
ValidateEventListener.java:172)
        at org.hibernate.action.EntityIdentityInsertAction.preInsert(Entity
IdentityInsertAction.java:142)
        at org.hibernate.action.EntityIdentityInsertAction.execute(EntityId
entityInsertAction.java:65)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrR
eplicate(AbstractSaveEventListener.java:321)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(Ab
stractSaveEventListener.java:204)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGenera
tedId(AbstractSaveEventListener.java:130)
        at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGenerat
edId(EJB3PersistEventListener.java:49)
        at org.hibernate.event.def.DefaultPersistEventListener.entityIsTran
sient(DefaultPersistEventListener.java:154)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(De
faultPersistEventListener.java:110)
        at org.hibernate.event.def.DefaultPersistEventListener.onPersist(De
faultPersistEventListener.java:61)
        at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)

        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
        at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEnti
tyManagerImpl.java:220)
        at sun.reflect.GeneratedMethodAccessor454.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethod
AccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jboss.seam.persistence.EntityManagerInvocationHandler.invoke
(EntityManagerInvocationHandler.java:46)
        at $Proxy550.persist(Unknown Source)
        at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:84)
        at com.mycompany.action.UserHome.persist(

Answer

kraftan picture kraftan · Nov 1, 2010

Each InvalidStateException has an array of InvalidValue. Each InvalidValue shows which property of the bean you want to persist is violated. As @Arthur pointed out correctly, violations of Java persistence annotations end up in InvalidStateExceptions, too.

To debug your problem, I would temporarily catch the InvalidStateException in com.mycompany.action.UserHome.persist and print out each InvalidValue as follows:

} catch (InvalidStateException e) {
    for (InvalidValue invalidValue : e.getInvalidValues()) {
        log.info("Instance of bean class: " + invalidValue.getBeanClass().getSimpleName() +
                 " has an invalid property: " + invalidValue.getPropertyName() +
                 " with message: " + invalidValue.getMessage()));
    }
}