Error relating two tables in the database

0

I have a web project in java, in which I am mapping towers and patchpanels, where a tower has several patches and a patch has only one tower attached to it. This relationship is all ok, now the patch port relationship, where a patch has multiple ports and a port has only one patch bound to it is giving error. By registering new patch and adding equipment to the ports it saves the equipment but does not bind to which patch panel it is linked to. As you can see below, where description would be the equipment connected to the port:

Mymodelpatchpanel:'packagemodels;

importjava.util.List;importjavax.persistence.CascadeType;importjavax.persistence.Entity;importjavax.persistence.EnumType;importjavax.persistence.Enumerated;importjavax.persistence.JoinColumn;importjavax.persistence.ManyToOne;importjavax.persistence.OneToMany;importplay.data.validation.Required;importplay.data.validation.Unique;importplay.db.jpa.Model;importjavax.persistence.Entity;importjavax.persistence.EnumType;importjavax.persistence.Enumerated;importjavax.persistence.Temporal;importjavax.persistence.TemporalType;importjavax.persistence.Transient;@EntitypublicclassPatchpanelextendsModel{@RequiredpublicStringnome;@RequiredpublicStringmac;@Required@UniquepublicStringip;@RequiredpublicStringnumPortas;@OneToMany(cascade={CascadeType.ALL},mappedBy="patchpanels")
public List<Porta> portas;

@ManyToOne
@JoinColumn(name="torre_id")
public Torre torre;

@Enumerated(EnumType.STRING)
public Status status;

public Patchpanel() {
    status = Status.ATIVO;
}
}

' my ports model:

package models;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class Porta extends Model {

@Required
public String descricao;

@Enumerated(EnumType.STRING)
public Status status;

@ManyToOne
public Patchpanel patchpanels;

public Porta() {
    status = Status.ATIVO;
}
}

My patchpanel driver where the patch is saved:

public static void salvarPatchpanel(@Valid Patchpanel patchpanel, List<String> portas) {

    if (validation.hasErrors()) {
        params.flash();
        validation.keep();
        formPatchpanel();
    }

    for (String porta : portas) {
        patchpanel.portas = new ArrayList<Porta>();
        Porta p = new Porta();
        p.descricao = porta;
        patchpanel.portas.add(p);
        patchpanel.save();
    }
    String mensagem = "Cadastro realizado com sucesso!";
    flash.success(mensagem);
    //patchpanel.save();
    listagemPatchpanel(null);

}
    
asked by anonymous 14.07.2017 / 23:22

1 answer

0

Is not it missing a @JoinColumn(name="NOME_DA_COLUNA") in this code?

@ManyToOne
public Patchpanel patchpanels;
    
17.07.2017 / 03:39