Hibernate-envers para auditoria

Estou utilizando o envers para auditoria.

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-envers</artifactId>
		</dependency>

Para insert, update e delete está normal e funciona corretamente na tabela de aud.

Para mostrar na tela não:

Este é o código:

public Collection<AtividadeRevisaoDTO> revisoes(final String id) {
        log.info("revisoes - id: " + id);
        final AuditQuery auditQuery = auditReader.createQuery().forRevisionsOfEntity(Atividade.class, false, true);
        auditQuery.add(AuditEntity.id().eq(id));
        return preencher.dtoAuditoria(auditQuery.getResultList());
    }

Model:

package br.com.ghnetsoft.smga.model;

import static javax.persistence.EnumType.STRING;
import static lombok.AccessLevel.PROTECTED;
import static org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.AuditTable;
import org.hibernate.envers.Audited;

import br.com.ghnetsoft.principal.auditoria.AuditableBase;
import br.com.ghnetsoft.principal.auditoria.Principal;
import br.com.ghnetsoft.principal.enuns.DiaSemanaEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@ToString(of = { "id", "nomeDescricao", "diaSemanaAbertura", "diaSemanaFechamento" })
@EqualsAndHashCode(of = "id", callSuper = false)
@Entity
@Setter
@Getter
@Builder
@Table(name = "TAB_ATIVIDADE")
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor(access = PROTECTED)
@Cache(usage = NONSTRICT_READ_WRITE)
@Audited
@AuditOverride(forClass = Principal.class)
@AuditTable(schema = "LOGS", value = "TAB_ATIVIDADE_AUD")
public class Atividade extends AuditableBase {

    private static final long serialVersionUID = -2887397793364939616L;
    @Id
    @Column(name = "PK_ATIVIDADE")
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;
    @ManyToOne(targetEntity = ServicoFila.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "FK_SERVICO_FILA")
    private ServicoFila servicoFila;
    @Column(name = "DS_NOME_DESCRICAO")
    private String nomeDescricao;
    @Enumerated(STRING)
    @Column(name = "ST_DIA_SEMANA_ABERTURA")
    private DiaSemanaEnum diaSemanaAbertura;
    @Enumerated(STRING)
    @Column(name = "ST_DIA_SEMANA_FECHAMENTO")
    private DiaSemanaEnum diaSemanaFechamento;
}

Converter para DTO

public Collection<AtividadeRevisaoDTO> dtoAuditoria(final Collection<Object> entidades) {
        final Collection<AtividadeRevisaoDTO> retorno = new ArrayList<>();
        entidades.forEach(entidade -> retorno.add(dtoAuditoriaSimples((Object[]) entidade)));
        return retorno;
    }

    private AtividadeRevisaoDTO dtoAuditoriaSimples(final Object[] objeto) {
        final Atividade entidade = (Atividade) objeto[0];
        final DefaultRevisionEntity defaultRevisionEntity = (DefaultRevisionEntity) objeto[1];
        final RevisionType revisionType = (RevisionType) objeto[2];
        String diaSemanaAbertura = null;
        String diaSemanaAberturaDescricao = null;
        String diaSemanaFechamento = null;
        String diaSemanaFechamentoDescricao = null;
        if (entidade.getDiaSemanaAbertura() != null) {
            diaSemanaAbertura = entidade.getDiaSemanaAbertura().name();
            diaSemanaAberturaDescricao = entidade.getDiaSemanaAbertura().getDescricao();
        }
        if (entidade.getDiaSemanaFechamento() != null) {
            diaSemanaFechamento = entidade.getDiaSemanaFechamento().name();
            diaSemanaFechamentoDescricao = entidade.getDiaSemanaFechamento().getDescricao();
        }
        final AtividadeRevisaoDTO dto = AtividadeRevisaoDTO.builder().nomeServicoFila(entidade.getServicoFila().getNomeDescricao()).idServicoFila(entidade.getServicoFila().getId()).diaSemanaAbertura(diaSemanaAbertura).diaSemanaAberturaDescricao(diaSemanaAberturaDescricao).diaSemanaFechamento(diaSemanaFechamento).diaSemanaFechamentoDescricao(diaSemanaFechamentoDescricao).nomeDescricao(entidade.getNomeDescricao()).build();
        dto.setIdString(entidade.getId());
        dto.setDataHoraAbertura(entidade.getDataHoraCadastro());
        dto.setDataHoraAtualizacao(entidade.getDataHoraMovimentacao());
        dto.setStatusDoRegistro(preencherEnunStatusRegistro(entidade));
        return dto;
    }

Só que mostra este erro no log:

2022-11-07 08:22:29 - b.c.g.s.c.service.AtividadeService - revisoes - id: 26795584-eef6-429c-aeb8-da384140fcc4
Hibernate: select atividade_0_.pk_atividade as pk_ativi1_0_0_, atividade_0_.rev as rev2_0_0_, defaultrev1_.rev as rev1_9_1_, atividade_0_.revtype as revtype3_0_0_, atividade_0_.ts_cadastro as ts_cadas4_0_0_, atividade_0_.ts_movimentacao as ts_movim5_0_0_, atividade_0_.st_situacao as st_situa6_0_0_, atividade_0_.ip_movimentacao as ip_movim7_0_0_, atividade_0_.cd_login_movimentacao as cd_login8_0_0_, atividade_0_.st_registro as st_regis9_0_0_, atividade_0_.tp_operacao as tp_oper10_0_0_, atividade_0_.st_dia_semana_abertura as st_dia_11_0_0_, atividade_0_.st_dia_semana_fechamento as st_dia_12_0_0_, atividade_0_.ds_nome_descricao as ds_nome13_0_0_, atividade_0_.fk_servico_fila as fk_serv14_0_0_, defaultrev1_.revtstmp as revtstmp2_9_1_ from logs.tab_atividade_aud atividade_0_ cross join revinfo defaultrev1_ where atividade_0_.pk_atividade=? and atividade_0_.rev=defaultrev1_.rev order by atividade_0_.rev asc
Hibernate: select servicofil0_.pk_servico_fila as pk_servi1_7_, servicofil0_.rev as rev2_7_, servicofil0_.revtype as revtype3_7_, servicofil0_.ts_cadastro as ts_cadas4_7_, servicofil0_.ts_movimentacao as ts_movim5_7_, servicofil0_.st_situacao as st_situa6_7_, servicofil0_.ip_movimentacao as ip_movim7_7_, servicofil0_.cd_login_movimentacao as cd_login8_7_, servicofil0_.st_registro as st_regis9_7_, servicofil0_.tp_operacao as tp_oper10_7_, servicofil0_.st_dia_semana_abertura as st_dia_11_7_, servicofil0_.st_dia_semana_fechamento as st_dia_12_7_, servicofil0_.ds_nome_descricao as ds_nome13_7_, servicofil0_.ds_prefixo as ds_pref14_7_, servicofil0_.nr_senha_final as nr_senh15_7_, servicofil0_.nr_senha_inicial as nr_senh16_7_, servicofil0_.fk_pessoa_agencia as fk_pess17_7_ from logs.tab_servico_fila_aud servicofil0_ where servicofil0_.rev=(select max(servicofil1_.rev) from logs.tab_servico_fila_aud servicofil1_ where servicofil1_.rev<=? and servicofil0_.pk_servico_fila=servicofil1_.pk_servico_fila) and servicofil0_.revtype<>? and servicofil0_.pk_servico_fila=?
2022-11-07 08:22:47 - b.c.g.p.resource.MensagensRetorno - Unable to find br.com.ghnetsoft.smga.model.ServicoFila with id 1
javax.persistence.EntityNotFoundException: Unable to find br.com.ghnetsoft.smga.model.ServicoFila with id 1
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$JpaEntityNotFoundDelegate.handleEntityNotFound(EntityManagerFactoryBuilderImpl.java:163)
	at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:286)
	at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:181)
	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310)
	at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45)
	at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95)
	at br.com.ghnetsoft.smga.model.ServicoFila$HibernateProxy$w2zQbQfl.getNomeDescricao(Unknown Source)
	at br.com.ghnetsoft.smga.crud.preencher.AtividadePreencher.dtoAuditoriaSimples(AtividadePreencher.java:78)
	at br.com.ghnetsoft.smga.crud.preencher.AtividadePreencher.lambda$1(AtividadePreencher.java:58)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at br.com.ghnetsoft.smga.crud.preencher.AtividadePreencher.dtoAuditoria(AtividadePreencher.java:58)
	at br.com.ghnetsoft.smga.crud.service.AtividadeService.revisoes(AtividadeService.java:123)
	at br.com.ghnetsoft.smga.crud.service.AtividadeService$$FastClassBySpringCGLIB$$573f17b0.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
	at br.com.ghnetsoft.smga.crud.service.AtividadeService$$EnhancerBySpringCGLIB$$9f23c097.revisoes(<generated>)
	at br.com.ghnetsoft.smga.crud.resource.AtividadeResource.revisao(AtividadeResource.java:146)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:118)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:158)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter(OAuth2AuthenticationProcessingFilter.java:176)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92)
	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at br.com.ghnetsoft.smga.crud.config.SmpleCORSFilter.doFilter(SmpleCORSFilter.java:48)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)

O que pode ser ?

Pelo log do erro aparentemente você está buscando uma entidade com ID inexistente!

1 curtida

Dados tab_servico_fila, o que existe o PK_SERVICO_FILA igual a 1.

Mas consulta ele faz em tabela logs.tab_servico_fila_aud, para buscar o objeto. Esta tabela não tem auditoria, porque não foi mudando o registro

select servicofil0_.pk_servico_fila as pk_servi1_7_, servicofil0_.rev as rev2_7_, servicofil0_.revtype as revtype3_7_, servicofil0_.ts_cadastro as ts_cadas4_7_, servicofil0_.ts_movimentacao as ts_movim5_7_, servicofil0_.st_situacao as st_situa6_7_, servicofil0_.ip_movimentacao as ip_movim7_7_, servicofil0_.cd_login_movimentacao as cd_login8_7_, servicofil0_.st_registro as st_regis9_7_, servicofil0_.tp_operacao as tp_oper10_7_, servicofil0_.st_dia_semana_abertura as st_dia_11_7_, servicofil0_.st_dia_semana_fechamento as st_dia_12_7_, servicofil0_.ds_nome_descricao as ds_nome13_7_, servicofil0_.ds_prefixo as ds_pref14_7_, servicofil0_.nr_senha_final as nr_senh15_7_, servicofil0_.nr_senha_inicial as nr_senh16_7_, servicofil0_.fk_pessoa_agencia as fk_pess17_7_ 
from logs.tab_servico_fila_aud servicofil0_

Não deveria ser da tabela tab_servico_fila ?

model

package br.com.ghnetsoft.smga.model;

import static javax.persistence.EnumType.STRING;
import static lombok.AccessLevel.PROTECTED;
import static org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.AuditTable;
import org.hibernate.envers.Audited;

import br.com.ghnetsoft.principal.auditoria.AuditableBase;
import br.com.ghnetsoft.principal.auditoria.Principal;
import br.com.ghnetsoft.principal.enuns.DiaSemanaEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@ToString(of = { "id", "nomeDescricao", "diaSemanaAbertura", "diaSemanaFechamento" })
@EqualsAndHashCode(of = "id", callSuper = false)
@Entity
@Setter
@Getter
@Builder
@Table(name = "TAB_ATIVIDADE")
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor(access = PROTECTED)
@Cache(usage = NONSTRICT_READ_WRITE)
@Audited
@AuditOverride(forClass = Principal.class)
@AuditTable(schema = "LOGS", value = "TAB_ATIVIDADE_AUD")
public class Atividade extends AuditableBase {

    private static final long serialVersionUID = -2887397793364939616L;
    @Id
    @Column(name = "PK_ATIVIDADE")
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;
    @ManyToOne(targetEntity = ServicoFila.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "FK_SERVICO_FILA")
    private ServicoFila servicoFila;
    @Column(name = "DS_NOME_DESCRICAO")
    private String nomeDescricao;
    @Enumerated(STRING)
    @Column(name = "ST_DIA_SEMANA_ABERTURA")
    private DiaSemanaEnum diaSemanaAbertura;
    @Enumerated(STRING)
    @Column(name = "ST_DIA_SEMANA_FECHAMENTO")
    private DiaSemanaEnum diaSemanaFechamento;
}

DLL da tabela: tab_atividade_aud

O problema possivelmente ocorre porquê o hibernate dispara 2 consultas e não somente uma, se você observar o log ele olha para 2 tabelas distintas, 1 consulta para cada uma delas.

O “X” da questão é você avaliar se realmente faz sentido as duas consultas serem disparadas da forma como estão sendo, caso sim, precisa ajustar a lógica de auditoria para afetar sempre ambas as entidades, caso contrário, precisa avaliar a forma como você está relacionando suas entidades para que o hibernate faça somente a consulta na tabela desejada.

1 curtida

Entendi.