Doubt about dependency injection in Customer Systems of Hibernate

Asked

Viewed 107 times

1

I wonder if there is any way I can inject resources into an Hibernate Event Listener using vraptor 3.5. I wish I could simulate the behavior of a Rigger that we have in the database. And this Listener would update the database.

I have the following object:

@Entity
@EntityListeners(value=ContaEntradaListener.class)
@Table(name = "nfeide", schema = "coliseunfe")
@SequenceGenerator(name = "coliseunfe.gen_idnfeide", sequenceName = "coliseunfe.gen_idnfeide")
public class Nfeide implements java.io.Serializable{

private static final long serialVersionUID = -4072081791666953260L;
private long idnfeide;
private Filial filial;
private Funcuser funcuser;
private long nnf;
private Long nnfnota;
private Long nnfnotahomo;
private int cnf;
private Tipopagamento tipopagamento;
private Modelo modelo;
private Serie serie;
private LocalDateTime demi;
private LocalDateTime dsaient;
private LocalTime hsaient;
private Integer tpnfe;
etc...

As you can see there I have declared an Event Listener, which follows below:

public class ContaEntradaListener{

private ContaentradaRepository contaentradaRepository;

public ContaEntradaListener() {
    /*contaentradaRepository = new ContaentradaBusiness(null, null);*/
}

@PreUpdate  
public void preUpdate(Object object){

    Nfeide nfeide = (Nfeide) object;
    char statusnota = nfeide.getStatusnota();
    List<Nfecontaentrada> nfecontaentradas = new ArrayList<>(nfeide.getNfecontaentradas());

    for(Nfecontaentrada nfecontaentrada: nfecontaentradas){
        Contaentrada contaentrada = nfecontaentrada.getContaentrada();

        if(statusnota == 'a'){
            String descricao = "NRO. NOTA: " + nfeide.getNnf();
            contaentradaRepository.atualizaContaentradaStatus(contaentrada.getIdcontaentrada(), "p");
            contaentradaRepository.atualizaContaentradaDescricao(contaentrada.getIdcontaentrada(), descricao);

        } else if(statusnota == 'c'){
            contaentradaRepository.atualizaContaentradaStatus(contaentrada.getIdcontaentrada(), "n");
        }
    }
}
}

I know the question may be a bit silly, but it would be interesting for me to find a solution to this question of transforming triggers into java, to help with maintenance. Since I’ve been thanking

No answers

Browser other questions tagged

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