Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从MySql存储过程/函数获取到JPQL的结果_Mysql_Jpa_Jpql - Fatal编程技术网

无法从MySql存储过程/函数获取到JPQL的结果

无法从MySql存储过程/函数获取到JPQL的结果,mysql,jpa,jpql,Mysql,Jpa,Jpql,这是我的存储函数代码: CREATE DEFINER=`root`@`localhost` FUNCTION `func`() RETURNS int(11) LANGUAGE SQL NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT '' BEGIN DECLARE total INT DEFAULT 0; select count(*) INTO total from stu

这是我的存储函数代码:

CREATE DEFINER=`root`@`localhost` FUNCTION `func`()
    RETURNS int(11)
    LANGUAGE SQL
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
DECLARE total INT DEFAULT 0;
select count(*) INTO total from students;
RETURN total;
END
Java代码:

query=em.createNativeQuery("{ SELECT func() }");  
        String s=(String) query.getSingleResult();
        System.out.println(s);
但ir给出了一个例外:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ SELECT func() }' at line 1
Error Code: 1064
Call: { SELECT func() }
Query: DataReadQuery(sql="{ SELECT func() }")
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ SELECT func() }' at line 1
Error Code: 1064
Call: { SELECT func() }
Query: DataReadQuery(sql="{ SELECT func() }")
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:377)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:516)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
    at org.ceynamon.oregano.datamigration.Test.main(Test.java:26)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;

不需要
SELECT funct()
周围的大括号

不需要
SELECT funct()
周围的大括号