Dependency Injection Doubt on hibernate event listener

1

I wonder if there is any way I can inject features into a Hibernate Event Listener using vraptor 3.5. I wanted to be able to simulate the behavior of a trigger that we have in the database. And this Listener would do an update on the bank.

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:

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 kind of beast, but it would be interesting to find a solution to this question of turning triggers into java, to help with maintenance. Since there is thank you

    
asked by anonymous 10.06.2015 / 16:00

0 answers