EntityManager.createStoredProcedureQuery()未解析

时间:2017-07-29 07:13:47

标签: spring hibernate jpa

我有Spring 4.1.0.Final,JPA hibernate-jpa-2.1-api和MySql。我正在使用它来开发REST API。现在我需要调用存储过程。我必须确保EntityManager.createStoredProcedureQuery()用于调用存储过程。此功能在JPA 2.1中可用。我已经有JPA 2.1但仍然EntityManager.createStoredProcedureQuery()无法解析。粘贴maven配置的快照。

能告诉我可能出现的问题:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.test</groupId>
   <artifactId>TESTAPI</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>TESTAPI</name>
   <properties>
      <java-version>1.8</java-version>
      <org.springframework-version>4.2.5.RELEASE</org.springframework-version>
      <org.springframework-security-version>4.1.1.RELEASE</org.springframework-security-version>
      <org.springframework-security-oauth-version>2.0.10.RELEASE</org.springframework-security-oauth-version>
      <org.aspectj-version>1.6.10</org.aspectj-version>
      <org.slf4j-version>1.6.6</org.slf4j-version>
      <failOnMissingWebXml>false</failOnMissingWebXml>
   </properties>
   <dependencies>
      <!-- Spring -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-core</artifactId>
         <version>${org.springframework-version}</version>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-web</artifactId>
         <version>${org.springframework-version}</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-tx</artifactId>
         <version>${org.springframework-version}</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.6</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-core</artifactId>
         <version>4.1.4.Final</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-validator</artifactId>
         <version>4.1.0.Final</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
      <dependency>
         <groupId>org.hibernate.javax.persistence</groupId>
         <artifactId>hibernate-jpa-2.1-api</artifactId>
         <version>1.0.0.Final</version>
      </dependency>
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-entitymanager</artifactId>
         <version>4.1.0.Final</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
      <!-- >dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.1.0.Final</version>
        </dependency-->
      <!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence -->
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-jdbc</artifactId>
         <version>${org.springframework-version}</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-orm</artifactId>
         <version>${org.springframework-version}</version>
      </dependency>
      <dependency>
         <groupId>javax.transaction</groupId>
         <artifactId>jta</artifactId>
         <version>1.1</version>
      </dependency>
      <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-io</artifactId>
         <version>1.3.2</version>
      </dependency>
   </dependencies>
   <build>
      <finalName>TESTAPI</finalName>
   </build>
   <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
</project>

2 个答案:

答案 0 :(得分:1)

您有两种选择。

1)hibernate-jpa-2.0-api中排除hibernate-entitymanager

  <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-entitymanager</artifactId>
     <version>4.1.0.Final</version>
     <exclusions>
       <exclusion>  
         <groupId>org.hibernate.javax.persistence</groupId>
         <artifactId>hibernate-jpa-2.0-api</artifactId>
       </exclusion>
     </exclusions> 
  </dependency>

2)将hibernate-entitymanager的版本升级到包含2.1 JPA api的第一个版本作为其依赖项:

  <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-entitymanager</artifactId>
     <version>4.3.0.Final</version> 
  </dependency>

答案 1 :(得分:0)

对不起,您的回复很晚。希望这样可以解决您的问题,但是如果您使用的是JPA升级,它可能对新手有所帮助。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.2.Final</version>
        <scope>provided</scope>
    </dependency>

默认情况下,如果我们通过此命令创建Maven项目,我们将面临该问题...

MVN原型:generate -DarchetypeArtifactId = jboss-javaee6-webapp -DarchetypeGroupId = org.jboss.spec.archetypes -DgroupId = com.example.helloworld -DartifactId = projectpath -DinteractiveMode = false

谢谢