2011-09-05 58 views
0

现在我真的输了...或困惑......我得到这个类递归引用给映射问题

  package co.com.adv.Salarix2.core.nominaprocessor.model; 
      // Generated 23/08/2011 03:13:44 PM by Hibernate Tools 3.2.4.GA 

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

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

       private int idArbol; 
       private int idNodo; 
       private int idHoja; 

       public NodoId() { 
       } 

       public NodoId(int idArbol, int idNodo, int idHoja) { 
        this.idArbol = idArbol; 
        this.idNodo = idNodo; 
        this.idHoja = idHoja; 
       } 

       @Column(name = "Id_Arbol", nullable = false) 
       public int getIdArbol() { 
        return this.idArbol; 
       } 

       public void setIdArbol(int idArbol) { 
        this.idArbol = idArbol; 
       } 

       @Column(name = "Id_Nodo", nullable = false) 
       public int getIdNodo() { 
        return this.idNodo; 
       } 

       public void setIdNodo(int idNodo) { 
        this.idNodo = idNodo; 
       } 

       @Column(name = "Id_Hoja", nullable = false) 
       public int getIdHoja() { 
        return this.idHoja; 
       } 

       public void setIdHoja(int idHoja) { 
        this.idHoja = idHoja; 
       } 

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

        return (this.getIdArbol() == castOther.getIdArbol()) 
          && (this.getIdNodo() == castOther.getIdNodo()) 
          && (this.getIdHoja() == castOther.getIdHoja()); 
       } 

       public int hashCode() { 
        int result = 17; 

        result = 37 * result + this.getIdArbol(); 
        result = 37 * result + this.getIdNodo(); 
        result = 37 * result + this.getIdHoja(); 
        return result; 
       } 

       public String getStringRep() { 
        return this.idArbol + "-" + this.idHoja + "-" + this.idNodo; 
       } 

      } 

如果我把最后的方法......

   public String getStringRep() { 
        return this.idArbol + "-" + this.idHoja + "-" + this.idNodo; 
       } 

它抛出马平异常:

部署IN ERROR: 部署 “persistence.unit:的unitName = Salarix2.ear/Salarix2.jar#Salarix2” 是错误的,由于以下原因(S):org.hibern未引用co.com.adv.Salarix2.core.nominaprocessor.model.Nodo.nodo引用co.com.adv.Salarix2.core.nominaprocessor.model.Nodo的ate.AnnotationException:referencedColumnNames(Id_Arbol,Id_ Nodo,Id_Hoja)到一个单一的属性

但如果我删除它的方法部署好....为什么发生这种情况?

+0

现在我真的很困惑...我mnaged解决porblem ...但即时通讯看到这种行为...我最终与类 –

回答

0

这是因为Hibernate使用Reflection并认为类是“bean”。 Bean有一个getter和setter的标准命名法,如果你有一个像getStringRep这样的getter,hibernate会尝试找到一个名为StringRep的属性 - 你没有 - 为了避免这种情况只为非持久属性使用非标准名称例如stringRep()而不是getStringRep()(或使用@Transient关于getter的注释)。这应该可以解决你的问题。

+0

greeeat !!!我终于回到原来生成的类......最后意识到发生了什么......但直到现在......我真的明白为什么发生了!非常感谢你munch! –