【问题标题】:Exception with SpringJPA native querySpringJPA 本机查询异常
【发布时间】:2018-01-05 23:25:02
【问题描述】:

当我尝试执行我的native query 时,我面临以下异常:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你有一个 SQL 语法错误;检查与您对应的手册 MySQL 服务器版本,用于在 'f 附近使用正确的语法, codigoleyenda cl、tipocomprobante tc、moneda m、cliente c、tipotaxigv ttig, t' 在第 1 行

我的仓库如下-

@Repository
public interface FacturaRepository extends JpaRepository<Factura, Integer>, CrudRepository<Factura, Integer>{
    @Query(value="select " + 
            "f.facId," + 
            "facBaja," + 
            "f.facEnvioSunat," + 
            "f.facEnvioServidor," + 
            "f.facEstadoEnvioCorreo," + 
            "f.facFechaRespuesta," + 
            "f.facRuta," + 
            "f.facSubTotal," + 
            "f.facInafecta," + 
            "f.facExonerada," + 
            "f.facGratuita," + 
            "f.facGravada," + 
            "f.facPercepcion," + 
            "f.facOtrosTributos," + 
            "f.facDescuento," + 
            "cl.codLeyCodigo," + 
            "f.facLeyenda," + 
            "f.facDetraccion," + 
            "f.facNroSerie," + 
            "f.facNroCorrelativo," + 
            "f.facFechaEmision," + 
            "tc.tipComCodigo,"+ 
            "m.monCodigo,"+  
            "ub.ubiDepartamento," + 
            "ub.ubiProvincia," + 
            "ub.ubiDistrito," + 
            "ub.ubiCodigo," + 
            "p.parRuta," + 
            "s.sucDireccionFiscal," + 
            "s.sucRuc," + 
            "s.sucTipoDocumento," + 
            "s.sucPais," + 
            "s.sucRazonSocial," + 
            "c.cliCondicionDomicilio," + 
            "c.cliDireccionFiscal," + 
            "c.cliEstado," + 
            "c.cliNumeroDocumento," + 
            "c.cliRazonSocial," + 
            "td.tipDocCodigo," + 
            "f.facIgv," + 
            "f.facIsc," + 
            "ttig.tipTaxIgvCodigo," + 
            "ttis.tipTaxIscCodigo," + 
            "f.facOtrosConceptos," + 
            "oc.otrConCodigo," + 
            "f.facTaxIgvPorcentaje," + 
            "f.facTaxIscPorcentaje," + 
            "f.facHashcode," + 
            "f.facNombreZip," + 
            "f.facTotal," + 
            "f.facRetencion," + 
            "f.facPlaca" + 
            "from factura f, codigoleyenda cl, tipocomprobante tc, moneda m, cliente c, tipotaxigv ttig, tipotaxisc ttis, otrosconceptos oc," + 
            "tipodocumento td, sucursal s, ubigeo ub, parametros p" + 
            "where c.tipDocId = td.tipDocId and  f.sucId=s.sucId and s.ubiId=ub.ubiId and s.parId=p.parId" + 
            "and f.codLeyId=cl.codLeyId and f.tipComId=tc.tipComId  and f.monId=m.monId and f.cliId=c.cliId and " + 
            "f.tipTaxIgvId=ttig.tipTaxIgvId and f.tipTaxIscId=ttis.tipTaxIscId and f.OtrConId=oc.otrConId and f.facId=?1", nativeQuery=true)
            FacturaXmlDto getFacturaXml(int facId);

此查询在 mysql 上运行良好,但遇到 SpringJPA 异常,我需要有关此问题的帮助。

【问题讨论】:

    标签: java mysql sql spring spring-data-jpa


    【解决方案1】:

    对于此类问题,您需要给出例外情况。但从仅仅看它,检查你的空间。您肯定需要在以下行的结束引号之前添加一个空格:

    "f.facPlaca" +
    "tipodocumento td, sucursal s, ubigeo ub, parametros p" + 
    "where c.tipDocId = td.tipDocId and  f.sucId=s.sucId and s.ubiId=ub.ubiId and s.parId=p.parId" +
    

    如果没有空格,该行的最后一个单词会与下一行的第一个单词对齐。此外,在您的代码中,您可能希望打印结果查询,然后将该查询复制并粘贴到您的数据库浏览器中,看看会发生什么。

    【讨论】:

    • 谢谢,我已经正确查询了,但是还是有错误,显然 jpa 无法将数据传递给不是我实体的对象
    猜你喜欢
    • 1970-01-01
    • 2012-03-29
    • 2015-03-10
    • 1970-01-01
    • 2018-07-13
    • 2020-06-29
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多