2017-07-29 178 views
-1

我有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配置的快照。EntityManager.createStoredProcedureQuery()未解决

能否请你让我知道什么可能是问题:

<?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> 
+0

编译通过createStoredProcedureQuery()在EntityManager中不存在的错误。 –

+0

编译器“扔”!所以你在类路径中有一个JPA 2.0 API jar!无法获得简单 –

+0

已经JPA 2.1 POM: org.hibernate.javax.persistence 的Hibernate JPA-2.1-API 1.0.0.Final

回答

1

你有两个选择。

1)无论排除hibernate-jpa-2.0-apihibernate-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)升级休眠-的EntityManager的版本,以含有2.1 JPA API作为第一版本其依赖关系:

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

但我已经在我的pom文件中有JPA 2.1。 –