About implementation using spring

Asked

Viewed 90 times

1

Hello, I need a help, I have a bank with two tables 1-Institution 2-People, for that I created in the model these 2 classes do not know if it is the right way more I did so. I created the Repository and extended the Institution classes (look at the image) so far so good.inserir a descrição da imagem aqui

In Service I created the method to save, but in Controller I can not call the class People because I extended the Institution so I can not save the data of the form of people, I do not know if I understand, I have not much knowledge probably to implementing in a wrong way, as I could do ? inserir a descrição da imagem aqui inserir a descrição da imagem aqui

1 answer

0


Greetings,

You need to create a Repository for Pessoas tbm:

@Repository
public interface PessoasRepository extends JpaRepository<Pessoas, Integer> {

}

This way you will use this repository to save People objects. You can even use the same service (I believe it is not recommended), but create different methods in your service or do a method overload that will be the way you want, for example:

@Service
public class Service {

    @Autowired
    EventoRepository eventoRepository; //recomendo trocar o nome desse repositório para InstituicaoRepository

    @Autowired
    PessoasRepository pessoasRepository;

    public void save(Instituicao instituicao) {
        eventoRepository.save(instituicao);
    }

    //UTILIZANDO A SOBRECARGA
    public void save(Pessoas pessoas) {
        pessoasRepository.save(pessoas);
    }

    //RESTANTE DO SEU CÓDIGO

}

I hope I’ve helped.

Browser other questions tagged

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