JPA实体中没有自动检测Maven的验证 [英] No autodetection of JPA Entities in maven-verify

查看:174
本文介绍了JPA实体中没有自动检测Maven的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我把persistence.xml中在src /测试/ META-INF文件夹,自动检测的实体不与Maven的验证工作。当persistence.xml中位于的src / main / META-INF文件夹它的作品。

在Eclipse中运行测试在两种情况下工作。

有没有办法让自动检测工作的行家,验证时的persistence.xml是位于src / test文件夹?

persistence.xml中:

 <持久性的xmlns =htt​​p://java.sun.com/xml/ns/persistence版本=1.0>  <持久性单位名称=单位的交易类型=RESOURCE_LOCAL>
    <性状>
      <! - 扫描注释类和Hibernate映射XML文件 - >
      <属性名=hibernate.archive.autodetectionVALUE =类/>
    < /性状>
  < /持久化部>< /持久>


解决方案

在默认情况下自动检测适用于实体在同一类路径项作为的persistence.xml 。它可以通过配置< JAR文件方式> 元素

要启用自动检测正确时的persistence.xml 的src /测试/资源/ META-INF 我用下面的技巧:

的persistence.xml

 <持久性...>
    <持久性单位...>
        < JAR-文件> $ {project.build.outputDirectory}< / JAR-文件>
        ...
    < /持久化部>
< /持久>

的pom.xml - 启用的src /测试/资源资源过滤:

 <项目...>
    ...
    <建立>
        < testResources>
            < testResource>
                <&目录GT;的src /测试/资源< /目录>
                <过滤和GT;真< /过滤>
            < / testResource>
        < / testResources>
    < /构建>
< /项目>

虽然我不知道如果你的的persistence.xml 实际上是在的src /测试/ META-INF

If I put the persistence.xml in the src/test/META-INF folder, autodetection the Entities does not work with maven-verify. When the persistence.xml is located in the src/main/META-INF folder it works.

Running the tests in eclipse works in both cases.

Is there a way to get autodetection to work for maven-verify when the persistence.xml is located in the src/test Folder?

persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

  <persistence-unit name="Unit" transaction-type="RESOURCE_LOCAL">
    <properties>
      <!-- Scan for annotated classes and Hibernate mapping XML files -->
      <property name="hibernate.archive.autodetection" value="class" />
    </properties>
  </persistence-unit>

</persistence>

解决方案

By default autodetection works for entities in the same classpath item as persistence.xml. It can be configured by <jar-file> elements.

To enable correct autodetection when persistence.xml is in src/test/resources/META-INF I use the following trick:

persistence.xml:

<persistence ...>
    <persistence-unit ...>
        <jar-file>${project.build.outputDirectory}</jar-file>
        ...
    </persistence-unit>
</persistence>

pom.xml - enable resource filtering for src/test/resources:

<project ...>
    ...
    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>
</project>

Though I'm not sure how to use it if your persistence.xml is actually in src/test/META-INF.

这篇关于JPA实体中没有自动检测Maven的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆