开发者

Recursive reference in table with compossed Id gives mapping problem

Now im really lost...or confused...I got this class

            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 getI开发者_C百科dNodo() {
                    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;
                }

            }

If i keep the last method...

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

It throws the maping exception:

DEPLOYMENTS IN ERROR: Deployment "persistence.unit:unitName=Salarix2.ear/Salarix2.jar#Salarix2" is in error due to the following reason(s): org.hibernate.AnnotationException: referencedColumnNames(Id_Arbol, Id_ Nodo, Id_Hoja) of co.com.adv.Salarix2.core.nominaprocessor.model.Nodo.nodo referencing co.com.adv.Salarix2.core.nominaprocessor.model.Nodo not mapped to a single property

but if I remove the method it deployes ok....Why this happen???


This is because Hibernate uses Reflection and considers that Classes are "beans". Beans have a standard nomenclature for getters and setters, if you have a getter like getStringRep, hibernate will try to find a property called StringRep - which you don't have - To avoid that just use non-standard names for non-persistence properties, for example stringRep() instead of getStringRep() (or use @Transient annotation over getter). That should solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜