javax.persistence.EntityManager缺少一个方法

时间:2014-02-04 10:29:48

标签: java maven jpa

我最近厌倦了在我的java web项目中修复maven依赖项的问题,我从存储库文件夹中删除了所有内容,之后我在eclipse中执行了“maven update project”并且问题得到解决,但是出现了其他错误。 createNamedQuery(String, Class<T>)接口中不再存在我使用javax.persistence.EntityManager的方法。我做了一些研究,我怀疑maven已经将JPA实现版本改为JPA 1.0,这非常烦人,而且我真的不知道如何解决这个问题。我没有更改pom.xml中的任何内容,我注意到的唯一更改是javax.persistence包现在来自jboss-as-connector maven工件的ejb3 jar。我该如何解决这个问题?

抱歉:我刚发现ejb3-persistence来自hibernate包。

编辑:

pom.xml文件:

    ...
<properties>
    <jboss.provided.jar>compile</jboss.provided.jar>
</properties>

<!-- JBoss repository for JMS stuff -->
<repositories>
    <repository>
        <id>JBoss repository</id>
        <url>http://repository.jboss.org/nexus/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <!-- Provides better parameterized tests than those provided by junit -->
    <dependency>
        <groupId>pl.pragmatists</groupId>
        <artifactId>JUnitParams</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <!-- Required for SpringJUnit4ClassRunner in IntegrationTests -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- Required for SpringockitoContextLoader in IntegrationTests -->
    <dependency>
        <groupId>org.kubek2k</groupId>
        <artifactId>springockito-annotations</artifactId>
        <version>1.0.8</version>
        <scope>test</scope>
    </dependency>
    <!-- Required for created the hsql database in IntegrationTests -->
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.1</version>
        <scope>test</scope>
    </dependency>
    <!-- Required for Selenium WebDriver automated tests -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.33.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>1.4.01</version>
        <scope>test</scope>
    </dependency>

    THIS IS PROBABLY THE ROOT OF ALL EVIL
    <!-- JBoss Seam - stuff for JMS Queue on JBoss -->
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-connector</artifactId>
        <version>6.1.0.Final</version>
    </dependency>


    <!-- Required when running the integration tests -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <!-- aspectjrt and aspectjweaver both required for @Autowired annotation 
        to work -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.7.3</version>
    </dependency>

    <!-- Required for spring bean proxying to work in integration tests -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-nodep</artifactId>
        <version>2.1_3</version>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <!-- Required for @RequestMapping annotation -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Use the same hibernate and Mysql versions as those on the JBoss server -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${org.hibernate.version}</version>
        <scope>${jboss.provided.jar}</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.0.1.Final</version>
        <scope>${jboss.provided.jar}</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.22</version>
        <scope>${jboss.provided.jar}</scope>
    </dependency>

    <!-- Use slf4j and log4j for logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <scope>${jboss.provided.jar}</scope>
    </dependency>

    <!-- Required for communication with exchange -->
    <dependency>
        <groupId>com.microsoft.ewsjavaapi</groupId>
        <artifactId>exchange-ws-api</artifactId>
        <version>1.1.5.2</version>
    </dependency>
    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>1.3.17</version>
    </dependency>
    <!-- end of dependencies for exchange -->

    <!-- Required for FileUtils -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>

    <!-- Required for StringUtils -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.1</version>
    </dependency>
</dependencies>
<build>
    <finalName>cat-webapp</finalName>

...

2 个答案:

答案 0 :(得分:0)

  1. 要找出这个类来自哪个库,只需要调用   Thread.currentThread()。getContextClassLoader()。的getResource( “的javax /持久/ EntityManager.class”)

  2. 要查看调用的依赖关系 mvn依赖:树

答案 1 :(得分:0)

替换此依赖项:

<dependency>
    <groupId>org.jboss.jbossas</groupId>
    <artifactId>jboss-as-connector</artifactId>
    <version>6.1.0.Final</version>
</dependency>

 <dependency>
    <groupId>org.jboss.as</groupId>
    <artifactId>jboss-as-connector</artifactId>
    <version>7.1.1.Final</version>
 </dependency>

您将使用hibernate-jpa-2.0-api方法从createNamedQuery获取EntityManager界面。