-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem updating related tables!
PostPosted: Fri May 07, 2010 8:30 am 
Newbie

Joined: Fri May 07, 2010 8:13 am
Posts: 2
I have a many-to-one relationship between "Matriculas" and "Titulares", so that a "Matricula" contains a single "Titular" (See mapping)

Following a query for "Matriculas" shows a list of result with editable fields (h: inputText) where one of them is the description of "Titular" (matriculas.titulares.titular)

When you edit this field and saving the result .. what I'm doing is retrieved the full object "Titular" associated with this description to recover the key. And once I have the object "Titular" complete, I set the attribute "Titular" of the "Matricula" to contain the new "Titular."

The problem is that instead of updating the registry in the new "Titular" received, ie change its associated key for the new .. what its doing is to modify the description of the Titular associated with the old key with the new description, ie, if the Matricula was associated with the Titular 1 - aaaaa and I to update the registry, I've passed the Titular 2 - bbbbb to change key 1 for 2 .. what it does is update the description of de first Titular with de second keeping the same key associated with the Titular in the Matricula.


I think the problem is mapping entities .. ¿?¿?¿?

put them down here:

Code:
@Entity
@Table(name="titulares")
public class Titulares  implements java.io.Serializable {

     private Integer id;
     private String titular;
     private List<Matriculas> matriculasList = new ArrayList<Matriculas>(0);

    public Titulares() {
    }
   
    public Titulares(String titular) {
        this.titular = titular;
    }

    public Titulares(String titular, List<Matriculas> matriculasList) {
       this.titular = titular;
       this.matriculasList = matriculasList;
    }

    @Id @GeneratedValue   
    @Column(name="ID", unique=true, nullable=false, length=10)
    public Integer getId() {
        return this.id;
    }
   
    public void setId(Integer id) {
        this.id = id;
    }
   
   @DataDefinition(descriptionColumn=true)
    @Column(name="TITULAR", nullable=false, length=45)
    public String getTitular() {
        return this.titular;
    }
   
    public void setTitular(String titular) {
        this.titular = titular;
    }

   @OneToMany(fetch=FetchType.LAZY, mappedBy="titulares")
    public List<Matriculas> getMatriculasList() {
        return this.matriculasList;
    }
   
    public void setMatriculasList(List<Matriculas> matriculasList) {
        this.matriculasList = matriculasList;
    }


}



Code:
@Entity
@Table(name = "MATRICULAS", schema = "CARLOTA")
public class Matriculas implements java.io.Serializable {

   private Integer id;
   private String matResProv;
   private String matResNum;
   private String matResLet;
   private String numRegistro;
   private Date fechaAlta;
   private Date fechaBaja;
   private String matOrdinaria;
   private Titulares titulares;
   private Organismos organismos;
   private String estado;
   private Integer version;


   public Matriculas() {
      System.out.println();
   }

   public Matriculas(Integer id, String matResProv, String matResNum, String matResLet, Date fechaAlta, Date fechaBaja, String matOrdinaria, String estado, Titulares titulares, Organismos organismos) {
      this.id = id;
      this.matResProv = matResProv;
      this.matResNum = matResNum;
      this.matResLet = matResLet;
      this.fechaAlta = fechaAlta;
      this.fechaBaja = fechaBaja;
      this.matOrdinaria = matOrdinaria;
      this.estado = estado;
      this.titulares = titulares;
      this.organismos = organismos;
   }

   public Matriculas(Integer id, String matResProv, String matResNum, String matResLet, String numRegistro, Date fechaAlta, Date fechaBaja, String matOrdinaria, Titulares titulares,
         Organismos organismos, String estado) {
      this.id = id;
      this.matResProv = matResProv;
      this.matResNum = matResNum;
      this.matResLet = matResLet;
      this.numRegistro = numRegistro;
      this.fechaAlta = fechaAlta;
      this.fechaBaja = fechaBaja;
      this.matOrdinaria = matOrdinaria;
      this.titulares = titulares;
      this.organismos = organismos;
      this.estado = estado;
   }

   @Id
   @Column(name = "ID", nullable = false, unique = true)
   @DataDefinition(naturalKeyColumn = true)
   public Integer getId() {
      return this.id;
   }

   public void setId(Integer id) {
      this.id = id;
   }
   
   
   @Version
   @Column(name = "VERSION")   
   public Integer getVersion() {
      return version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   @Column(name = "MAT_RES_PROV", length = 1, nullable = true)
   public String getMatResProv() {
      return this.matResProv;
   }

   public void setMatResProv(String matResProv) {
      this.matResProv = matResProv;
   }

   @DataDefinition(label = "Número", shortLabel = "Nº", descriptionColumn = true)
   @Column(name = "MAT_RES_NUM", length = 4, nullable = false)
   @Length(min=4, max=4)
   public String getMatResNum() {
      return this.matResNum;
   }

   public void setMatResNum(String matResNum) {
      this.matResNum = matResNum;
   }

   @Column(name = "MAT_RES_LET", length = 3, nullable = false)
   public String getMatResLet() {
      return this.matResLet;
   }

   public void setMatResLet(String matResLet) {
      this.matResLet = matResLet;
   }

   @Column(name = "NUM_REGISTRO", length = 20)
   @DataDefinition(label = "Número Registro", shortLabel = "NºRegistro")
   public String getNumRegistro() {
      return this.numRegistro;
   }

   public void setNumRegistro(String numRegistro) {
      this.numRegistro = numRegistro;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "FECHA_ALTA", nullable = false)
   @DataDefinition(label = "Fecha Alta", shortLabel = "F.Alta")
   public Date getFechaAlta() {
      return this.fechaAlta;
   }

   public void setFechaAlta(Date fechaAlta) {
      this.fechaAlta = fechaAlta;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "FECHA_BAJA", length = 11)
   @DataDefinition(label = "Fecha Baja", shortLabel = "F.Baja")
   public Date getFechaBaja() {
      return this.fechaBaja;
   }

   public void setFechaBaja(Date fechaBaja) {
      this.fechaBaja = fechaBaja;
   }

   @Column(name = "MAT_ORDINARIA", length = 10, nullable = true)
   @DataDefinition(label = "Matrícula Ordinaria", shortLabel = "Mat.Ordianaria")
   public String getMatOrdinaria() {
      return this.matOrdinaria;
   }

   public void setMatOrdinaria(String matOrdinaria) {
      this.matOrdinaria = matOrdinaria;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "TITULAR")
   public Titulares getTitulares() {
      return this.titulares;
   }

   public void setTitulares(Titulares titulares) {
      this.titulares = titulares;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ORGANISMO")
   public Organismos getOrganismos() {
      return this.organismos;
   }

   public void setOrganismos(Organismos organismos) {
      this.organismos = organismos;
   }

   @Column(name = "ESTADO", length = 20, nullable = false)
   @SelectItems(control = ControlType.Droplist, value = { @SelectItem(id = "PENDIENTE", value = "PENDIENTE", label = "Pendiente"),
         @SelectItem(id = "VERIFICADA", value = "VERIFICADA", label = "Verificada"), @SelectItem(id = "ADJUDICADA", value = "ADJUDICADA", label = "Adjudicada"),
         @SelectItem(id = "DENEGADA", value = "DENEGADA", label = "Denegada") })
   @DataDefinition(label = "Estado")
   public String getEstado() {
      return this.estado;
   }

   public void setEstado(String estado) {
      this.estado = estado;
   }

}



Por favor. necesito algo de ayuda.

PD: Sorry for my bad English and the translator of google.


Top
 Profile  
 
 Post subject: Re: Problem updating related tables!
PostPosted: Mon May 10, 2010 2:23 am 
Newbie

Joined: Fri May 07, 2010 8:13 am
Posts: 2
Please, i need some help with this problem!


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

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.