相关疑难解决方法(0)

我如何使用 spring 和 jpa 调用存储过程

我是使用 JPA 技术的 SPRING 新手。

我正在尝试调用用 mysql 5 编写的存储过程。当我尝试使用存储过程获取数据时,将其称为“喷出异常”。

org.springframework.dao.InvalidDataAccessApiUsageException: : 查询必须以ororg.hibernate.QueryException开头:嵌套例外是: : 查询必须以or开头: ]SELECTFROMcall [call st_proc_getusers()];java.lang.IllegalArgumentExceptionorg.hibernate.QueryExceptionSELECTFROMcall [call st_proc_getusers()

我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit  name="SPT3" transaction-type="RESOURCE_LOCAL">
            <mapping-file>META-INF/persistence-query.xml</mapping-file>
            <class>com.spt3.pojo.Users</class>
            <properties>
                    <property name="hibernate.dialect" value=">org.hibernate.dialect.MySQLDialect" />
                    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/spring_security" />
                    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                    <property name="hibernate.connection.username" value="user" />
                    <property name="hibernate.connection.password" value="pass" />
                    <property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
                    <property name="hibernate.max_fetch_depth" value="3"/>
                    <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
                    <property name="hibernate.query.substitutions" value="true …
Run Code Online (Sandbox Code Playgroud)

spring stored-procedures jpa

5
推荐指数
1
解决办法
3万
查看次数

使用Spring调用数据库函数

我需要通过 SQL 查询数据库的函数,就像这样简单

@Query("SELECT random()")

如何实现域/存储库服务方法来执行此操作?

java spring spring-data spring-data-jpa spring-boot

1
推荐指数
1
解决办法
9272
查看次数