Jpa审计不会在表审计中保存数据

时间:2017-12-18 12:56:52

标签: jpa spring-boot spring-data-jpa audit auditing

我必须在我的应用程序中实现审计..我正确地插入这些数据

enter image description here

但我想从我的实体中保存所有属性, 例如,名字,epigrafe,..和olthers。

我实施了这个方法但是没有工作,只是不保存atribut ..

让我们看..

@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "logradouros_historico", schema = "aud")
public class LogradourosHistorico {


        @Id
        @GeneratedValue
        private Long id;

        @ManyToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "id_logradouro")
        private Logradouros logradouro;


        @CreatedBy
        private String modificadoPor;


        @CreatedDate
        @Temporal(TemporalType.TIMESTAMP)
        private Date modifiedDate = new Date();

        @Enumerated(EnumType.STRING)
        private Acoes acao;


        @Column(name = "nome")
        private String nome; //nome do logradouro

        public LogradourosHistorico() {
            super();

        }




        public LogradourosHistorico(Logradouros logradouro, String modificadoPor, 
                Acoes acao) {
            super();
            this.logradouro = logradouro;
            this.modificadoPor = modificadoPor;
            this.acao = acao;
        }
   //getters and setters 

我的班级实体列表

public class LogradourosEntityListener {

    @PostPersist
    public void prePersist(Logradouros target) { 
        perform(target, Acoes.INSERTED);        
    }

    @PreUpdate
    public void preUpdate(Logradouros target) { 
         perform(target, Acoes.UPDATED);        
    }

    @PreRemove
    public void preRemove(Logradouros target) { 
        perform(target, Acoes.DELETED);

    }


    @Transactional()
    private void perform(Logradouros target, Acoes acao) {
        target.getNome();
        EntityManager entityManager = BeanUtil.getBean(EntityManager.class);
        entityManager.persist(new LogradourosHistorico(target, acao));

    } 
}

 my class Logradouros 

@Entity
@EntityListeners(LogradourosEntityListener.class)
@Table(name = "logradouros", schema = "glb",  uniqueConstraints= @UniqueConstraint(columnNames={"id_entidade", "idLogradouro"}))
public class Logradouros extends Auditable<String> implements Serializable  {

    private static final long serialVersionUID = 3703309412387185484L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int idLogradouro;

    @Column(name = "cep_geral")
    private String cepGeral;

    @Column(name = "epigrafe")
    private String epigrafe;

    @NotNull
    @Column(name = "nome")
    private String nome;

    @Column(name = "nome_exibicao")
    private String nomeExibicao;


    @JoinColumn(name = "id_entidade")
    @ManyToOne(/*cascade = CascadeType.ALL*/)
    private Entidades entidade;

    @NotNull
    @JoinColumn(name = "id_municipio")
    @ManyToOne(/*cascade = CascadeType.ALL*/)
    private Municipios municipio; 

    // gettrs and settrs 

所以我做错了因为我无法得到nome实体Logradouros

0 个答案:

没有答案