4 Replies Latest reply on Feb 20, 2011 6:21 AM by Feri Lauw

    org.hibernate.validator.InvalidStateException: validation failed for:

    Feri Lauw Newbie

      Hai All,


      When I Save error come :




      Caused by javax.servlet.ServletException with message: "#{saHome.persist}: org.hibernate.validator.InvalidStateException: validation failed for: org.fla.eStock.entity.Sa"





      I Try Override persist(), but still error.


      Could somebody help me?



      Thanks before.

        • 1. Re: org.hibernate.validator.InvalidStateException: validation failed for:
          Serkan Eskici Novice

          You seem to have validation errors in your entity that's why it cannot be saved.

          • 2. Re: org.hibernate.validator.InvalidStateException: validation failed for:
            Feri Lauw Newbie

            Dear Sir Serkan.


            I already check but it's seem all standard validation.
            Here is my Code :





            Sa Entity are :



            package org.fla.eStock.entity;
            
            // Generated Feb 9, 2011 8:24:36 AM by Hibernate Tools 3.2.5.Beta
            
            import static org.jboss.seam.ScopeType.SESSION;
            
            import java.math.BigDecimal;
            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.Id;
            import javax.persistence.Table;
            import javax.persistence.Temporal;
            import javax.persistence.TemporalType;
            import javax.persistence.UniqueConstraint;
            import org.hibernate.validator.Length;
            import org.hibernate.validator.NotNull;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            
            import javax.persistence.GeneratedValue;
            import static javax.persistence.GenerationType.IDENTITY;
            /**
             * Sa generated by hbm2java
             */
            @SuppressWarnings("serial")
            @Entity
            @Name("sa")  // Tambahan
            @Scope(SESSION) // Tambahan
            @Table(name = "sa", catalog = "eStock2011", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
            public class Sa implements java.io.Serializable
            {
            
               private SaId id;
               private int id_1;
               private String nama;
               private BigDecimal oa;
               private BigDecimal od;
               private BigDecimal ok;
               private BigDecimal awal;
               private BigDecimal jual;
               private BigDecimal retur;
               private String singkat;
               private BigDecimal komcash;
               private BigDecimal kom45;
               private BigDecimal kom75;
               private BigDecimal kom90;
               private Date tgl;
               private BigDecimal piutang;
               private BigDecimal piujt;
               private BigDecimal tagih;
               private BigDecimal tlbt0;
               private BigDecimal tlbt30;
               private BigDecimal tlbt60;
               private BigDecimal tlbt90;
               private BigDecimal tlbt99;
               private short lbr;
               private short lbrtjp;
               private short lbrjt;
               private int lbr30;
               private int lbr3060;
               private int lbr6090;
               private int lbr90;
               private long tagihlbt;
            
               public Sa()
               {
               }
            
               public Sa(SaId id, int id_1, String nama, BigDecimal oa, BigDecimal od, BigDecimal ok, BigDecimal awal, BigDecimal jual, BigDecimal retur, String singkat, BigDecimal komcash, BigDecimal kom45, BigDecimal kom75, BigDecimal kom90, Date tgl, BigDecimal piutang, BigDecimal piujt, BigDecimal tagih, BigDecimal tlbt0, BigDecimal tlbt30, BigDecimal tlbt60, BigDecimal tlbt90, BigDecimal tlbt99, short lbr, short lbrtjp, short lbrjt, int lbr30, int lbr3060, int lbr6090, int lbr90, long tagihlbt)
               {
                  this.id = id;
                  this.id_1 = id_1;
                  this.nama = nama;
                  this.oa = oa;
                  this.od = od;
                  this.ok = ok;
                  this.awal = awal;
                  this.jual = jual;
                  this.retur = retur;
                  this.singkat = singkat;
                  this.komcash = komcash;
                  this.kom45 = kom45;
                  this.kom75 = kom75;
                  this.kom90 = kom90;
                  this.tgl = tgl;
                  this.piutang = piutang;
                  this.piujt = piujt;
                  this.tagih = tagih;
                  this.tlbt0 = tlbt0;
                  this.tlbt30 = tlbt30;
                  this.tlbt60 = tlbt60;
                  this.tlbt90 = tlbt90;
                  this.tlbt99 = tlbt99;
                  this.lbr = lbr;
                  this.lbrtjp = lbrtjp;
                  this.lbrjt = lbrjt;
                  this.lbr30 = lbr30;
                  this.lbr3060 = lbr3060;
                  this.lbr6090 = lbr6090;
                  this.lbr90 = lbr90;
                  this.tagihlbt = tagihlbt;
               }
            
               @EmbeddedId
               @AttributeOverrides( { @AttributeOverride(name = "cabang", column = @Column(name = "cabang", nullable = false, length = 3)), 
               @AttributeOverride(name = "tahun", column = @Column(name = "tahun", nullable = false, length = 4)), 
               @AttributeOverride(name = "bulan", column = @Column(name = "bulan", nullable = false, length = 2)), 
               @AttributeOverride(name = "kode", column = @Column(name = "kode", nullable = false, length = 5)) })
               //@NotNull
               public SaId getId()
               {
                  return this.id;
               }
            
               public void setId(SaId id)
               {
                  this.id = id;
               }
            
               //@Column(name = "id", unique = true, nullable = false)
              
             
               //@Id
               @GeneratedValue(strategy = IDENTITY)
               @Column(name = "id", unique = true, nullable = false)
               public int getId_1()
               {
                  return this.id_1;
               }
            
               public void setId_1(int id_1)
               {
                  this.id_1 = id_1;
               }
             /*  @NotNull
               @Length(max = 20)*/
              // @Column(name = "nama", nullable = true, length = 20) 
               @Column(name = "nama", nullable = true, length = 20)
               //@NotNull
               @Length(max = 20)
               public String getNama()
               {
                  return this.nama;
               }
            
               public void setNama(String nama)
               {
                  this.nama = nama;
               }
            
               @Column(name = "oa", nullable = true, precision = 18)
               public BigDecimal getOa()
               {
                  return this.oa;
               }
            
               public void setOa(BigDecimal oa)
               {
                  this.oa = oa;
               }
            
               @Column(name = "od", nullable = true, precision = 18)  
               public BigDecimal getOd()
               {
                  return this.od;
               }
            
               public void setOd(BigDecimal od)
               {
                  this.od = od;
               }
            
               @Column(name = "ok", nullable = true, precision = 18)  
               public BigDecimal getOk()
               {
                  return this.ok;
               }
            
               public void setOk(BigDecimal ok)
               {
                  this.ok = ok;
               }
            
               @Column(name = "awal", nullable = true, precision = 18) 
               public BigDecimal getAwal()
               {
                  return this.awal;
               }
            
               public void setAwal(BigDecimal awal)
               {
                  this.awal = awal;
               }
            
               @Column(name = "jual", nullable = true, precision = 18)  
               public BigDecimal getJual()
               {
                  return this.jual;
               }
            
               public void setJual(BigDecimal jual)
               {
                  this.jual = jual;
               }
            
               @Column(name = "retur", nullable = true, precision = 18) 
               public BigDecimal getRetur()
               {
                  return this.retur;
               }
            
               public void setRetur(BigDecimal retur)
               {
                  this.retur = retur;
               }
            
               @Column(name = "singkat", nullable = true, length = 3)  
               @Length(max = 3)
               public String getSingkat()
               {
                  return this.singkat;
               }
            
               public void setSingkat(String singkat)
               {
                  this.singkat = singkat;
               }
            
               @Column(name = "komcash", nullable = true, precision = 12)  
               public BigDecimal getKomcash()
               {
                  return this.komcash;
               }
            
               public void setKomcash(BigDecimal komcash)
               {
                  this.komcash = komcash;
               }
            
               @Column(name = "kom45", nullable = true, precision = 12)  
               public BigDecimal getKom45()
               {
                  return this.kom45;
               }
            
               public void setKom45(BigDecimal kom45)
               {
                  this.kom45 = kom45;
               }
            
               @Column(name = "kom75", nullable = true, precision = 12)   
               public BigDecimal getKom75()
               {
                  return this.kom75;
               }
            
               public void setKom75(BigDecimal kom75)
               {
                  this.kom75 = kom75;
               }
            
               @Column(name = "kom90", nullable = true, precision = 12)  
               public BigDecimal getKom90()
               {
                  return this.kom90;
               }
            
               public void setKom90(BigDecimal kom90)
               {
                  this.kom90 = kom90;
               }
            
               @Temporal(TemporalType.DATE)
               @Column(name = "tgl", nullable = true, length = 10)   
               public Date getTgl()
               {
                  return this.tgl;
               }
            
               public void setTgl(Date tgl)
               {
                  this.tgl = tgl;
               }
            
               @Column(name = "piutang", nullable = true, precision = 18)   
               public BigDecimal getPiutang()
               {
                  return this.piutang;
               }
            
               public void setPiutang(BigDecimal piutang)
               {
                  this.piutang = piutang;
               }
            
               @Column(name = "piujt", nullable = true, precision = 18)   
               public BigDecimal getPiujt()
               {
                  return this.piujt;
               }
            
               public void setPiujt(BigDecimal piujt)
               {
                  this.piujt = piujt;
               }
            
               @Column(name = "tagih", nullable = true, precision = 18)   
               public BigDecimal getTagih()
               {
                  return this.tagih;
               }
            
               public void setTagih(BigDecimal tagih)
               {
                  this.tagih = tagih;
               }
            
               @Column(name = "tlbt0", nullable = true, precision = 18)  
               public BigDecimal getTlbt0()
               {
                  return this.tlbt0;
               }
            
               public void setTlbt0(BigDecimal tlbt0)
               {
                  this.tlbt0 = tlbt0;
               }
            
               @Column(name = "tlbt30", nullable = true, precision = 18)   
               public BigDecimal getTlbt30()
               {
                  return this.tlbt30;
               }
            
               public void setTlbt30(BigDecimal tlbt30)
               {
                  this.tlbt30 = tlbt30;
               }
            
               @Column(name = "tlbt60", nullable = true, precision = 18)   
               public BigDecimal getTlbt60()
               {
                  return this.tlbt60;
               }
            
               public void setTlbt60(BigDecimal tlbt60)
               {
                  this.tlbt60 = tlbt60;
               }
            
               @Column(name = "tlbt90", nullable = true, precision = 18)  
               public BigDecimal getTlbt90()
               {
                  return this.tlbt90;
               }
            
               public void setTlbt90(BigDecimal tlbt90)
               {
                  this.tlbt90 = tlbt90;
               }
            
               @Column(name = "tlbt99", nullable = true, precision = 18)  
               public BigDecimal getTlbt99()
               {
                  return this.tlbt99;
               }
            
               public void setTlbt99(BigDecimal tlbt99)
               {
                  this.tlbt99 = tlbt99;
               }
            
               @Column(name = "lbr", nullable = true, precision = 4, scale = 0)
               public short getLbr()
               {
                  return this.lbr;
               }
            
               public void setLbr(short lbr)
               {
                  this.lbr = lbr;
               }
            
               @Column(name = "lbrtjp", nullable = true, precision = 4, scale = 0)
               public short getLbrtjp()
               {
                  return this.lbrtjp;
               }
            
               public void setLbrtjp(short lbrtjp)
               {
                  this.lbrtjp = lbrtjp;
               }
            
               @Column(name = "lbrjt", nullable = true, precision = 4, scale = 0)
               public short getLbrjt()
               {
                  return this.lbrjt;
               }
            
               public void setLbrjt(short lbrjt)
               {
                  this.lbrjt = lbrjt;
               }
            
               @Column(name = "lbr30", nullable = true, precision = 6, scale = 0)
               public int getLbr30()
               {
                  return this.lbr30;
               }
            
               public void setLbr30(int lbr30)
               {
                  this.lbr30 = lbr30;
               }
            
               @Column(name = "lbr3060", nullable = true, precision = 6, scale = 0)
               public int getLbr3060()
               {
                  return this.lbr3060;
               }
            
               public void setLbr3060(int lbr3060)
               {
                  this.lbr3060 = lbr3060;
               }
            
               @Column(name = "lbr6090", nullable = true, precision = 6, scale = 0)
               public int getLbr6090()
               {
                  return this.lbr6090;
               }
            
               public void setLbr6090(int lbr6090)
               {
                  this.lbr6090 = lbr6090;
               }
            
               @Column(name = "lbr90", nullable = true, precision = 6, scale = 0)
               public int getLbr90()
               {
                  return this.lbr90;
               }
            
               public void setLbr90(int lbr90)
               {
                  this.lbr90 = lbr90;
               }
            
               @Column(name = "tagihlbt", nullable = true, precision = 12, scale = 0)
               public long getTagihlbt()
               {
                  return this.tagihlbt;
               }
            
               public void setTagihlbt(long tagihlbt)
               {
                  this.tagihlbt = tagihlbt;
               }
            }
            






            SaId entity are :





            package org.fla.eStock.entity;
            
            // Generated Feb 9, 2011 8:24:36 AM by Hibernate Tools 3.2.5.Beta
            
            import javax.persistence.Column;
            import javax.persistence.Embeddable;
            import org.hibernate.validator.Length;
            import org.hibernate.validator.NotNull;
            
            /**
             * SaId generated by hbm2java
             */
            @SuppressWarnings("serial")
            @Embeddable
            public class SaId implements java.io.Serializable
            {
            
               private String cabang;
               private String tahun;
               private String bulan;
               private String kode;
            
               public SaId()
               {
               }
            
               public SaId(String cabang, String tahun, String bulan, String kode)
               {
                  this.cabang = cabang;
                  this.tahun = tahun;
                  this.bulan = bulan;
                  this.kode = kode;
               }
            
               //@Column(name = "cabang", nullable = false, length = 3)
               //@NotNull
               //@Length(max = 3)
               @Column(name = "cabang", nullable = false, length = 3) 
               @Length(max = 3)
               public String getCabang()
               {
                  return this.cabang;
               }
            
               public void setCabang(String cabang)
               {
                  this.cabang = cabang;
               }
            
               @Column(name = "tahun", nullable = false, length = 4)
               @NotNull
               @Length(max = 4)
               //@Column(name = "tahun", nullable = false, length = 4)  
               //@Length(max = 4)
               public String getTahun()
               {
                  return this.tahun;
               }
            
               public void setTahun(String tahun)
               {
                  this.tahun = tahun;
               }
            
               @Column(name = "bulan", nullable = false, length = 2)
               @NotNull
               @Length(max = 2)
               //@Column(name = "bulan", nullable = false, length = 2)  
               //@Length(max = 2)
               public String getBulan()
               {
                  return this.bulan;
               }
            
               public void setBulan(String bulan)
               {
                  this.bulan = bulan;
               }
            
               @Column(name = "kode", nullable = false, length = 5)
               //@NotNull
               @Length(max = 5)
               public String getKode()
               {
                  return this.kode;
               }
            
               public void setKode(String kode)
               {
                  this.kode = kode;
               }
            
               public boolean equals(Object other)
               {
                  if ((this == other))
                     return true;
                  if ((other == null))
                     return false;
                  if (!(other instanceof SaId))
                     return false;
                  SaId castOther = (SaId) other;
            
                  return ((this.getCabang() == castOther.getCabang()) || (this.getCabang() != null && castOther.getCabang() != null && this.getCabang().equals(castOther.getCabang()))) && ((this.getTahun() == castOther.getTahun()) || (this.getTahun() != null && castOther.getTahun() != null && this.getTahun().equals(castOther.getTahun()))) && ((this.getBulan() == castOther.getBulan()) || (this.getBulan() != null && castOther.getBulan() != null && this.getBulan().equals(castOther.getBulan()))) && ((this.getKode() == castOther.getKode()) || (this.getKode() != null && castOther.getKode() != null && this.getKode().equals(castOther.getKode())));
               }
            
               public int hashCode()
               {
                  int result = 17;
            
                  result = 37 * result + (getCabang() == null ? 0 : this.getCabang().hashCode());
                  result = 37 * result + (getTahun() == null ? 0 : this.getTahun().hashCode());
                  result = 37 * result + (getBulan() == null ? 0 : this.getBulan().hashCode());
                  result = 37 * result + (getKode() == null ? 0 : this.getKode().hashCode());
                  return result;
               }
            }
            





            SaHome are :



            package org.fla.eStock.session;
            
            import org.fla.eStock.entity.*;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Transactional;
            import org.jboss.seam.framework.EntityHome;
            //import org.jboss.seam.persistence.PersistenceProvider;
            
            @SuppressWarnings("serial")
            @Name("saHome")
            public class SaHome extends EntityHome<Sa>
            {
               private String bulanToNum;
            
               public String getBulanToNum()
               {
                  return bulanToNum;
               }
            
               public void setBulanToNum(String bulan)
               {
            
                  this.bulanToNum = bulan;
                  if (bulan.equalsIgnoreCase("Januari"))
                  {
                     this.bulanToNum="01";
                  }
                  else if (bulan.equalsIgnoreCase("Februari"))
                  {
                     this.bulanToNum="02";
                  }
                  else if (bulan.equalsIgnoreCase("Maret"))
                  {
                     this.bulanToNum="03";
                  }
                  else if (bulan.equalsIgnoreCase("April"))
                  {
                     this.bulanToNum="04";
                  }
                  else if (bulan.equalsIgnoreCase("Mei"))
                  {
                     this.bulanToNum="05";
                  }
                  else if (bulan.equalsIgnoreCase("Juni"))
                  {
                     this.bulanToNum="06";
                  }
                  else if (bulan.equalsIgnoreCase("Juli"))
                  {
                     this.bulanToNum="07";
                  }
                  else if (bulan.equalsIgnoreCase("Agustus"))
                  {
                     this.bulanToNum="08";
                  }
                  else if (bulan.equalsIgnoreCase("September"))
                  {
                     this.bulanToNum="09";
                  }
                  else if (bulan.equalsIgnoreCase("Oktober"))
                  {
                     this.bulanToNum="10";
                  }
                  else if (bulan.equalsIgnoreCase("November"))
                  {
                     this.bulanToNum="11";
                  }
                  else if (bulan.equalsIgnoreCase("Desember"))
                  {
                     this.bulanToNum="12";
                  }
               }
            
               @In(required = false)
               protected Cabang cabang;
            
               public void setSaId(SaId id)
               {
                  setBulanToNum(cabang.getBulan());
                  System.out.println("::: Test Cabang :::");
                  System.out.println("Test Cabang Nama : " + cabang.getNama());
                  System.out.println("Test Cabang Tahun : " + cabang.getTahun());
            
                  System.out.println("Test Cabang Bulan : " + getBulanToNum());
                  System.out.println("Test Cabang Kota : " + cabang.getKota());
                  id.setCabang(cabang.getKota());
                  id.setTahun(cabang.getTahun());
                  id.setBulan(getBulanToNum());
                  System.out.println("::: Test SaId :::");
                  System.out.println("Test Cabang Kota : " + id.getCabang());
                  System.out.println("Test Cabang Tahun : " + id.getTahun());
                  System.out.println("Test Cabang Bulan : " + id.getBulan());
                  setId(id);
               }
            
               public SaId getSaId()
               {
                  return (SaId) getId();
               }
            
               public SaHome()
               {
               }
            
               @Override
               public void create()
               {
                  super.create();
                  setSaId(new SaId());
               }
             
               @Override
               public boolean isIdDefined()
               {
                  if (getSaId().getCabang() == null || "".equals(getSaId().getCabang()))
                     return false;
                  if (getSaId().getTahun() == null || "".equals(getSaId().getTahun()))
                     return false;
                  if (getSaId().getBulan() == null || "".equals(getSaId().getBulan()))
                     return false;
                  if (getSaId().getKode() == null || "".equals(getSaId().getKode()))
                     return false;
                  return true;
               }
            
               @Override
               protected Sa createInstance()
               {
                  Sa sa = new Sa();
                  sa.setId(new SaId());
                  return sa;
               }
            
               public void load()
               {
                  if (isIdDefined())
                  {
                     wire();
                  }
               }
            
               public void wire()
               {
                  getInstance();
               }
            
               public boolean isWired()
               {
                  return true;
               }
            
               public Sa getDefinedInstance()
               {
                  return isIdDefined() ? getInstance() : null;
               }
            
            }
            
            





            Could you help me?
            Thanks u so much


            • 3. Re: org.hibernate.validator.InvalidStateException: validation failed for:
              Rob Shepherd Newbie

              You have a length attribute on a @Column annotation for a Date type.  Are you sure this is valid?

              • 4. Re: org.hibernate.validator.InvalidStateException: validation failed for:
                Feri Lauw Newbie

                Hi Sir Rob,


                I found the solutions sir Rob.





                the problem is : i need to get value of field into other class that i must save into table.



                About @Column Date is fine nothing wrong with that. But you give me lesson about Date, so i modify annotation from :



                @Temporal(TemporalType.DATE)
                @Column(name = "tgl", nullable = true, length = 10)   
                @NotNull



                and i replace a simple code into :



                @Basic @Temporal(TemporalType.DATE)



                i hope iam not wrong :)





                But the solution is, i should use the overloading constructor too in method :


                @Override
                   protected Sa createInstance()
                   {
                      Sa sa = new Sa();
                      sa.setId(new SaId(getCaba(),getThn(),getBulanToNum()));
                      return sa;
                   }



                same as like u said before in :



                @Override
                   public void create()
                   {
                      super.create();
                      setBulanToNum(cabang.getBulan());
                      setCaba(cabang.getKota());
                      setThn(cabang.getTahun());      
                      setSaId(new SaId(getCaba(),getThn(),getBulanToNum()));
                   }



                Thanks you so much Sir Rob.