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.  [ 1 post ] 
Author Message
 Post subject: Problem with multiple associatons between 2 classes
PostPosted: Fri Sep 14, 2007 6:59 am 
Newbie

Joined: Fri Sep 14, 2007 6:53 am
Posts: 1
I've got a class Aplicacion:

Code:
public class Aplicacion {

    private Integer id;

    private String nombre;

    private Usuario funcional = new Usuario();

    private Usuario tecnico = new Usuario();

    ...

    public Integer getId() {
        return id;
    }

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

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }


    public Usuario getFuncional() {
        return funcional;
    }

    public void setFuncional(Usuario funcional) {
        this.funcional = funcional;
    }

    public Usuario getTecnico() {
        return tecnico;
    }

    public void setTecnico(Usuario tecnico) {
        this.tecnico = tecnico;
    }

    ...

}


and the class Usuario:

Code:
public class Usuario {

    private Integer id;

    private String nombre;

    ...

    public Integer getId() {
        return id;
    }

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

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    ...

}


The hibernate mapping for Aplicacion is:

Code:
<hibernate-mapping>

        <class name="es.gva.san.jguiri.persistencia.Aplicacion" table="APLICACION">

                <id name="id" unsaved-value="-1">
                        <generator class="sequence">
                                aplicacion_id_seq
                        </generator>
                </id>

                <property name="nombre" />

                ...

                <many-to-one name="funcional" column="FK_FUNCIONAL" />
                <many-to-one name="tecnico" column="FK_TECNICO" />

        </class>
</hibernate-mapping>


and hibernate mapping for Usuario is:

Code:
<hibernate-mapping>

        <class name="es.gva.san.jguiri.persistencia.Usuario" table="USUARIO">

                <id name="id" unsaved-value="-1">
                        <generator class="sequence">
                                usuario_id_seq
                        </generator>
                </id>

                <property name="nombre" />

                ...


        </class>
</hibernate-mapping>


The JSP page is like that:

Code:
...

<html:text property="aplicacion.funcional.id"></html:text>

...

<html:text property="aplicacion.tecnico.id"></html:text>

...


The form is a DynaValidatorForm with a property of type Aplicacion.

The action is:

Code:
public ActionForward guardar(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        DynaActionForm dynaForm = (DynaActionForm) form;

        Aplicacion aplicacion = (Aplicacion) dynaForm.get("aplicacion");

        HibernateUtil.saveOrUpdate(aplicacion);

        return unspecified(mapping, form, request, response);
       
}


The class Usuario is a table with different persons. The class Aplicacion is associated with Usuario two times. One time through “tecnico” and another time through “funcional”.

When I select a Usuario for “tecnico” associaton and another different Usuario for “funcional” associaton and save there is no problem. When I select the same Usuario for “tecnico” and “funcional” and save it seems not to be a problem, but when next I select again a different Usuario for “tecnico” and for “funcional” and save… the “tecnico” and “functional” are the same, and allways the value of the “tecnico” (the last <html:text>)

I’m very confused and I have tried a lot of things (inherit “tecnico” and “funcional” from “Usuario”, using a diferent type of Form, …) and I have found no solution. Please, can anyone help me?


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

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.