How to edit an entity that has another jsf object?

Asked

Viewed 68 times

0

Good afternoon guys, I’m new to programming and I’m having problems with my jsf project. I have a client class that has an address object, with relationship @OneToOne to the address. I am able to query my address within the editing method. What I am not able to do is bring the data from my address and display on the customer’s registration page, and the customer’s data is normally loaded, but it does not bring the address.

Clientebean:

public String alterar() {
    try {
        this.cliNovo = null;
        this.cliNovo = fach.consultarCliente(this.cliente.getId());

        if(cliNovo.getEndereco().getId() != null) {
            cliNovo.getEndereco().getLogradouro();
            cliNovo.getEndereco().getNumero();
            cliNovo.getEndereco().getEstado();
            cliNovo.getEndereco().getBairro();
            cliNovo.getEndereco().getEstado();
        }
        fach.atualizarCliente(cliNovo);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return "/cadastrocli.xhtml?faces-redirect-true";
    //"cadastrocli";
}
  • Welcome Sopt! Sorry, but the way you put the question makes it hard to understand what you need. We don’t know the domain of your problem! If you can better specify your question, with emphasis on code, we can help you more.

  • So, the idea is to recover the data of a specific client and make the changes, what I am unable to return from the database and display in my form are the data that refer to the address, being the client has a fk of that address in a one-to-one relationship.

  • Hello Carlos, what Genos meant is that only with what we have above we can not diagnose what is happening. I assume that fach.consultarCliente is going to fetch the data in DB using correct JPA? It may be that your relationship is Lazy and there is no open session at view to recover the address data. Probably if you call getEndereco() at the right place this data will be loaded and propagated to the view, that said, without a MVCE it is difficult to give you a complete answer. You could update your question?

  • Put the entity implementation... Next to jpa annotations

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.