2011-09-05 57 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! –