-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.validator.InvalidStateException: ??
PostPosted: Wed Jun 24, 2009 11:06 pm 
Newbie

Joined: Thu Jun 22, 2006 12:11 am
Posts: 14
ok so i have the following entity, but when ever I try to create one and persist it I get the following error

Hibernate: 3.2.4.GA

Entity
Code:
// Generated 14-May-2009 10:51:17 PM by Hibernate Tools 3.2.4.GA

import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import org.hibernate.validator.NotNull;

import com.qorp.surge.enums.TeamPosition;

/**
* TeamMember generated by hbm2java
*/
@Entity
@Table(name = "team_member")
public class TeamMember implements java.io.Serializable {

   private TeamMemberId id;
   private int version;
   private Member member;
   private Team team;
   private Date joined;
   private Date departed;
   private TeamPosition position;

   public TeamMember() {
   }

   public TeamMember(TeamMemberId id, Member member, Team team, TeamPosition position) {
      this.id = id;
      this.member = member;
      this.team = team;
      this.position = position;
   }

   public TeamMember(TeamMemberId id, Member member, Team team, Date joined,
         Date departed, TeamPosition position) {
      this.id = id;
      this.member = member;
      this.team = team;
      this.joined = joined;
      this.departed = departed;
      this.position = position;
   }

   @EmbeddedId
   @AttributeOverrides( {
         @AttributeOverride(name = "memberId", column = @Column(name = "member_id", nullable = false)),
         @AttributeOverride(name = "teamId", column = @Column(name = "team_id", nullable = false)) })
   @NotNull
   public TeamMemberId getId() {
      return this.id;
   }

   public void setId(TeamMemberId id) {
      this.id = id;
   }

   @Version
   @Column(name = "version", nullable = false)
   public int getVersion() {
      return this.version;
   }

   public void setVersion(int version) {
      this.version = version;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "member_id", nullable = false, insertable = false, updatable = false)
   @NotNull
   public Member getMember() {
      return this.member;
   }

   public void setMember(Member member) {
      this.member = member;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "team_id", nullable = false, insertable = false, updatable = false)
   @NotNull
   public Team getTeam() {
      return this.team;
   }

   public void setTeam(Team team) {
      this.team = team;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "joined", length = 13)
   public Date getJoined() {
      return this.joined;
   }

   public void setJoined(Date joined) {
      this.joined = joined;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "departed", length = 13)
   public Date getDeparted() {
      return this.departed;
   }

   public void setDeparted(Date departed) {
      this.departed = departed;
   }

   @Enumerated( EnumType.STRING )
   @Column(name = "position", nullable = false)
   @NotNull
   public TeamPosition getPosition() {
      return this.position;
   }

   public void setPosition(TeamPosition position) {
      this.position = position;
   }

}


EmbeddedId class
Code:
// Generated 14-May-2009 10:51:17 PM by Hibernate Tools 3.2.4.GA

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* TeamMemberId generated by hbm2java
*/
@Embeddable
public class TeamMemberId implements java.io.Serializable {

   private int memberId;
   private int teamId;

   public TeamMemberId() {
   }

   public TeamMemberId(int memberId, int teamId) {
      this.memberId = memberId;
      this.teamId = teamId;
   }

   @Column(name = "member_id", nullable = false)
   public int getMemberId() {
      return this.memberId;
   }

   public void setMemberId(int memberId) {
      this.memberId = memberId;
   }

   @Column(name = "team_id", nullable = false)
   public int getTeamId() {
      return this.teamId;
   }

   public void setTeamId(int teamId) {
      this.teamId = teamId;
   }

   public boolean equals(Object other) {
      if ((this == other))
         return true;
      if ((other == null))
         return false;
      if (!(other instanceof TeamMemberId))
         return false;
      TeamMemberId castOther = (TeamMemberId) other;

      return (this.getMemberId() == castOther.getMemberId())
            && (this.getTeamId() == castOther.getTeamId());
   }

   public int hashCode() {
      int result = 17;

      result = 37 * result + this.getMemberId();
      result = 37 * result + this.getTeamId();
      return result;
   }

}



Enum
Code:
public enum TeamPosition {

   //CREATE TYPE team_position AS ENUM('leader','captain','member');
   
   LEADER,
   CAPTAIN,
   MEMBER;
   
}



and the error
Quote:
22:51:12,454 ERROR [application] org.hibernate.validator.InvalidStateException: validation failed for: com.qorp.surge.entity.TeamMember
javax.faces.el.EvaluationException: org.hibernate.validator.InvalidStateException: validation failed for: com.qorp.surge.entity.TeamMember
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:387)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.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(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)



now initially I thought it was to do with the @Length annotation on the position field, but I removed that and still the issue remains...


Top
 Profile  
 
 Post subject: Re: org.hibernate.validator.InvalidStateException: ??
PostPosted: Thu Jun 25, 2009 9:43 pm 
Newbie

Joined: Thu Jun 22, 2006 12:11 am
Posts: 14
ok so my issue was a bit of a conflict in annotations I believe

Code:
@ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "team_id", nullable = false, insertable = false, updatable = false)
   @NotNull
   public Team getTeam() {
      return this.team;
   }


@ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "member_id", nullable = false, insertable = false, updatable = false)
   @NotNull
   public Member getMember() {
      return this.member;
   }


both of these fields are not null, but are taken care of in the TeamMemberId, they are also both not updatable or insertable, but I believe the @NotNull hibernate annotation conflicts with the nullable=false in JPA @JoinColumn

anyway the way I found this out was to catch the InvalidStateException and there is a method called getInvalidValues which gives you the property names and the error message, which is this case were "cannot be null"

so its fixed :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.