Hibernate对实体执行不受控制的更新

i5desfxk  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(123)

调试在(org.hibernate.SQL和org.hibernate.type.descriptor.sql)上设置休眠日志时出现的问题。
我发现在业务逻辑结束后,执行更新时在实体中设置了错误的值。
我使用@Service@Repository(扩展JpaRepository)作为持久层(我将很快更新代码)。

A SELECT PRIOR TO DE WRONG UPDATE

[DEBUG] 2022-11-24 11:11:03.906 [pool-3-thread-1] SQL - select entidad0_.id as id1_41_1_, entidad0_.anonimo as anonimo2_41_1_, entidad0_.apellidos as apellido3_41_1_, entidad0_.centroSalud as centrosa4_41_1_, entidad0_.idComu as idcomu39_41_1_, entidad0_.conFoto as confoto5_41_1_, entidad0_.dirCp as dircp6_41_1_, entidad0_.dirLocalidad as dirlocal7_41_1_, entidad0_.dirNombre as dirnombr8_41_1_, entidad0_.dirNumero as dirnumer9_41_1_, entidad0_.dirPiso as dirpiso10_41_1_, entidad0_.direccion as direcci11_41_1_, entidad0_.documento as documen12_41_1_, entidad0_.empresa as empresa13_41_1_, entidad0_.idEstadoCiudadano as idestad40_41_1_, entidad0_.estudios as estudio14_41_1_, entidad0_.fechaCreacion as fechacr15_41_1_, entidad0_.fechaNacimiento as fechana16_41_1_, entidad0_.foto as foto17_41_1_, entidad0_.idBiblioteca as idbibli18_41_1_, entidad0_.idEntidad as identid19_41_1_, entidad0_.idFCM as idfcm20_41_1_, entidad0_.mail as mail21_41_1_, entidad0_.movil as movil22_41_1_, entidad0_.nia as nia23_41_1_, entidad0_.nombre as nombre24_41_1_, entidad0_.pais as pais25_41_1_, entidad0_.profesion as profesi26_41_1_, entidad0_.prueba as prueba27_41_1_, entidad0_.idPuestoImpresion as idpuest41_41_1_, entidad0_.saldoVirtual as saldovi28_41_1_, entidad0_.sexo as sexo29_41_1_, entidad0_.telefono as telefon30_41_1_, entidad0_.idTipoCiudadano as idtipoc42_41_1_, entidad0_.idTipoDocumento as idtipod43_41_1_, entidad0_.idTipoDocumentoTutor as idtipod44_41_1_, entidad0_.tipoEntidad as tipoent31_41_1_, entidad0_.idTipoTutor as idtipot45_41_1_, entidad0_.tokenTemporal as tokente32_41_1_, entidad0_.tutorApellido as tutorap33_41_1_, entidad0_.tutorDocumento as tutordo34_41_1_, entidad0_.tutorEmail as tutorem35_41_1_, entidad0_.tutorFechaNacimiento as tutorfe36_41_1_, entidad0_.tutorMovil as tutormo37_41_1_, entidad0_.tutorNombre as tutorno38_41_1_, entidad0_.user_id as user_id46_41_1_, entidad0_.idUsuarioCreador as idusuar47_41_1_, incidencia1_.idEntidad as identida2_77_3_, incidencia2_.id as idincide1_77_3_, incidencia2_.id as id1_75_0_, incidencia2_.conAdjuntos as conadjun2_75_0_, incidencia2_.descripcion as descripc3_75_0_, incidencia2_.direccion as direccio4_75_0_, incidencia2_.idEstado as idestad11_75_0_, incidencia2_.fecha as fecha5_75_0_, incidencia2_.idIncidencia as idincide6_75_0_, incidencia2_.imagen as imagen7_75_0_, incidencia2_.lat as lat8_75_0_, incidencia2_.lon as lon9_75_0_, incidencia2_.prioridad as priorid10_75_0_, incidencia2_.idTipoIncidencia as idtipoi12_75_0_, incidencia2_.idUsuarioAsignado as idusuar13_75_0_, incidencia2_.idUsuarioCreador as idusuar14_75_0_ from Entidades entidad0_ left outer join incidenciasCiudadanos incidencia1_ on entidad0_.id=incidencia1_.idEntidad left outer join Incidencia incidencia2_ on incidencia1_.idIncidencia=incidencia2_.id where entidad0_.id=?
[TRACE] 2022-11-24 11:11:03.906 [pool-3-thread-1] BasicBinder - binding parameter [1] as [INTEGER] - [229]
[DEBUG] 2022-11-24 11:11:03.936 [http-nio-8090-exec-6] SQL - select listaambit0_.idTipoCiudadano as idtipoci4_135_0_, listaambit0_.id as id1_135_0_, listaambit0_.id as id1_135_1_, listaambit0_.porcentajePago as porcenta2_135_1_, listaambit0_.idTipoAmbito as idtipoam3_135_1_, listaambit0_.idTipoCiudadano as idtipoci4_135_1_, ambito1_.id as id1_4_2_, ambito1_.color as color2_4_2_, ambito1_.comisionCompra as comision3_4_2_, ambito1_.comisionRecarga as comision4_4_2_, ambito1_.descripcion as descripc5_4_2_, ambito1_.icono as icono6_4_2_, ambito1_.idAmbito as idambito7_4_2_, ambito1_.mail as mail8_4_2_, ambito1_.nombre as nombre9_4_2_, ambito1_.orden as orden10_4_2_, ambito1_.permiteAcceso as permite11_4_2_, ambito1_.permiteCompra as permite12_4_2_, ambito1_.permiteRecarga as permite13_4_2_, ambito1_.tipocentro as tipocen14_4_2_, ambito1_.visible as visible15_4_2_, ambito1_.visibleGraficos as visible16_4_2_ from TiposCiudadanoAmbito listaambit0_ inner join Ambitos ambito1_ on listaambit0_.idTipoAmbito=ambito1_.id where listaambit0_.idTipoCiudadano=?
[TRACE] 2022-11-24 11:11:03.936 [http-nio-8090-exec-6] BasicBinder - binding parameter [1] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([id1_75_0_] : [INTEGER]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([anonimo2_41_1_] : [BOOLEAN]) - [false]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([apellido3_41_1_] : [VARCHAR]) - [Propiedades email revertidas a ]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([centrosa4_41_1_] : [BOOLEAN]) - [false]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idcomu39_41_1_] : [INTEGER]) - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([confoto5_41_1_] : [BOOLEAN]) - [true]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([dircp6_41_1_] : [VARCHAR]) - [41100]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([dirlocal7_41_1_] : [VARCHAR]) - [XXX]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([dirnombr8_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([dirnumer9_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([dirpiso10_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([direcci11_41_1_] : [VARCHAR]) - [Propiedades email revertidas a]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([documen12_41_1_] : [VARCHAR]) - [XXX]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([empresa13_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idestad40_41_1_] : [INTEGER]) - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([estudio14_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([fechacr15_41_1_] : [TIMESTAMP]) - [2021-01-14 11:17:51.0]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([fechana16_41_1_] : [TIMESTAMP]) - [2000-06-21 00:00:00.0]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([foto17_41_1_] : [VARCHAR]) - [user/C0024460D/foto.htm]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idbibli18_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([identid19_41_1_] : [VARCHAR]) - [C0024460D]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idfcm20_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([mail21_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([movil22_41_1_] : [VARCHAR]) - [444111222]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([nia23_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([nombre24_41_1_] : [VARCHAR]) - [Propiedades email revertidas a ]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([pais25_41_1_] : [VARCHAR]) - [ES]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([profesi26_41_1_] : [VARCHAR]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([prueba27_41_1_] : [BOOLEAN]) - [false]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idpuest41_41_1_] : [INTEGER]) - [1]

**GOOD VALUE [TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([saldovi28_41_1_] : [NUMERIC]) - [50.00]**

[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([sexo29_41_1_] : [VARCHAR]) - [MASCULINO]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([telefon30_41_1_] : [VARCHAR]) - [444777888]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idtipoc42_41_1_] : [INTEGER]) - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idtipod43_41_1_] : [INTEGER]) - [2]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idtipod44_41_1_] : [INTEGER]) - [2]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tipoent31_41_1_] : [INTEGER]) - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idtipot45_41_1_] : [INTEGER]) - [1]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tokente32_41_1_] : [VARCHAR]) - [uuid-something]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutorap33_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutordo34_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutorem35_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutorfe36_41_1_] : [TIMESTAMP]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutormo37_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([tutorno38_41_1_] : [VARCHAR]) - []
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([user_id46_41_1_] : [INTEGER]) - [229]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([idusuar47_41_1_] : [INTEGER]) - [null]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([identid19_41_1_] : [VARCHAR]) - [C0024460D]
[TRACE] 2022-11-24 11:11:03.966 [pool-3-thread-1] BasicExtractor - extracted value ([identida2_77_3_] : [INTEGER]) - [null]

... more queries nomehow expected ones ...

[DEBUG] 2022-11-24 11:11:05.894 [pool-3-thread-1] SQL - update Entidades set anonimo=?, apellidos=?, centroSalud=?, idComu=?, conFoto=?, dirCp=?, dirLocalidad=?, dirNombre=?, dirNumero=?, dirPiso=?, direccion=?, documento=?, empresa=?, idEstadoCiudadano=?, estudios=?, fechaCreacion=?, fechaNacimiento=?, foto=?, idBiblioteca=?, idEntidad=?, idFCM=?, mail=?, movil=?, nia=?, nombre=?, pais=?, profesion=?, prueba=?, idPuestoImpresion=?, saldoVirtual=?, sexo=?, telefono=?, idTipoCiudadano=?, idTipoDocumento=?, idTipoDocumentoTutor=?, tipoEntidad=?, idTipoTutor=?, tokenTemporal=?, tutorApellido=?, tutorDocumento=?, tutorEmail=?, tutorFechaNacimiento=?, tutorMovil=?, tutorNombre=?, idUsuarioCreador=? where id=?
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [1] as [BOOLEAN] - [false]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [2] as [VARCHAR] - [Propiedades email revertidas a ]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [3] as [BOOLEAN] - [false]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [4] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [5] as [BOOLEAN] - [true]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [6] as [VARCHAR] - [41100]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [7] as [VARCHAR] - [XXX]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [8] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [9] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [10] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [11] as [VARCHAR] - [Propiedades email revertidas a ]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [12] as [VARCHAR] - [22987668L]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [13] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [14] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [15] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [16] as [TIMESTAMP] - [2021-01-14 11:17:51.0]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [17] as [TIMESTAMP] - [2000-06-21 00:00:00.0]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [18] as [VARCHAR] - [user/C0024460D/foto.htm]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [19] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [20] as [VARCHAR] - [C0024460D]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [21] as [VARCHAR] - [dkAVD8sOQ96w8OKI2jHMGE:APA91bG95UutWvUnAomLD57ZCBArogJmGyZajG1BJA939Dl1Gelcgiy4YHHJnaho7JZWVhGBthTRbNX9Hq5LOpZ8B1ydC1pE4FSPuF8PEqI2BOS_sUFIl6FjxciNN4QJNFs9IHQkRSZF]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [22] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [23] as [VARCHAR] - [444111222]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [24] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [25] as [VARCHAR] - [Propiedades email revertidas a ]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [26] as [VARCHAR] - [ES]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [27] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [28] as [BOOLEAN] - [false]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [29] as [INTEGER] - [1]

**WRONG VALUE DETECTED [TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [30] as [NUMERIC] - [0.44]**

[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [31] as [VARCHAR] - [MASCULINO]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [32] as [VARCHAR] - [444777888]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [33] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [34] as [INTEGER] - [2]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [35] as [INTEGER] - [2]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [36] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [37] as [INTEGER] - [1]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [38] as [VARCHAR] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [39] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [40] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [41] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [42] as [TIMESTAMP] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [43] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [44] as [VARCHAR] - []
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [45] as [INTEGER] - [null]
[TRACE] 2022-11-24 11:11:05.894 [pool-3-thread-1] BasicBinder - binding parameter [46] as [INTEGER] - [229]

UPDATED服务层,我在其中执行所有保存操作。涉及的方法有:

  • anotacionesBonificarCompra存储的位置。
  • saldoCiudadano作为信息查询。
  • recalcularBonificacion与事务或持久性无关。
@Service
@Log4j2
public class ISaldoVirtualServiceImpl implements ISaldoVirtualService {

    @Autowired
    private IComprasService comprasService;
    @Autowired
    private IRecargasService recargasService;
    @Autowired
    private IEntidadService entidadService;
    @Autowired
    IHistorialCiudadanoService historialCiudadanoService;
    @Autowired
    IHistorialSaldoVirtualService historialSaldoVirtualService;
    @Autowired
    private ISolicitudSaldoVirtualCiudadanoService solicitudSaldoVirtualService;
    @Autowired
    private IAccionService accionService;
    @Autowired
    private IHistorialVentaService historialVentaService;

    @Override
    @Transactional(readOnly = true)
    public BigDecimal saldoCiudadano(String idEntidad, Integer ciudadanoId) {
        BigDecimal sumaCompras = comprasService.findByIdCiudadano(idEntidad).stream().map(x -> x.getImporte()).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal sumaRecargas = recargasService.findByIdCiudadano(idEntidad).stream().map(x -> x.getImporte()).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal sumaRecargasMasivas = solicitudSaldoVirtualService.findByIdCiudadanoValidada(ciudadanoId).stream().map(x -> x.getSolicitud().getSaldorecargar()).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);

        return sumaRecargas.add(sumaRecargasMasivas).subtract(sumaCompras);
    }

    @Override
    public CalculoBonificacion recalcularBonificacion(CalculoBonificacion calculo) {

        BigDecimal importeBonificacion = ApiUtils.porcentajeame(calculo.getEntradaBonificar().getImporteTotal(), calculo.getCampana().getPorcentaje());
        BigDecimal valorMaximoCliente  = calculo.getCampana().getLimiteCampanaCiudadano();

        BigDecimal valorBase = calculo.getSaldoCiudadano();

        valorBase = (valorBase.compareTo(calculo.getRecargasHechas()) > 0 ? valorBase : calculo.getRecargasHechas());
        
        if (valorBase.add(importeBonificacion).compareTo(valorMaximoCliente) > 0) {
            importeBonificacion = valorMaximoCliente.subtract(valorBase);
            if (importeBonificacion.compareTo(BigDecimal.ZERO) < 0) importeBonificacion = BigDecimal.ZERO;
        }

        calculo.setCantidadBonificar(importeBonificacion);
        return calculo;
    }

    @Override
    @Transactional
    public void anotacionesBonificarCompra(Recarga recarga, HistorialCiudadano historialCiudadano, HistorialSaldoVirtual hv, Accion accion, Entidad ciudadano) {
        
        entidadService.saveAndFlush(ciudadano);
       
        recargasService.save(recarga);
        recarga.setNumeroOperacion(ApiUtils.exaId("","d",9, recarga.getId())+ UniqueUtils.randomChar(3,UniqueUtils.MAYUS_CONSONANTS));
        recarga.setIdUso(ApiUtils.exaId("R","X",10, recarga.getId()));
        recargasService.save(recarga);

       
        historialCiudadanoService.save(historialCiudadano);
        historialSaldoVirtualService.save(hv);

        accionService.save(accion);
        accion.asignarIdAccion();
        accionService.save(accion);
    }

    @Override
    @Transactional
    public void anotacionesCobrarTokenSaldoVirtual(Compra compra, HistorialVentas historialVentas, HistorialCiudadano historialCiudadano, HistorialSaldoVirtual hv, Accion accion, Entidad ciudadano) {
        entidadService.save(ciudadano);

        comprasService.onlySave(compra);
        compra.asignarIdUso();
        comprasService.onlySave(compra);

        historialVentaService.save(historialVentas);
        historialCiudadanoService.save(historialCiudadano);
        historialSaldoVirtualService.save(hv);
        accionService.save(accion);
        accion.asignarIdAccion();
        accionService.save(accion);

    }

    

}

更新2:

我已经将 service.保存(...)方法放在控制器代码上(没有使用@Transactional对它们进行分组)。发生了相同的行为。
有什么建议可以进一步调查解决这个问题吗?

dfddblmv

dfddblmv1#

我不能完全理解您的问题,但是将下面的语句添加到您的application.properties中可能会帮助您识别更新查询。因此,您可以看到由Hibernate运行的查询

spring.jpa.show-sql=true

相关问题