【问题标题】:Ignoring Datasource during roundtrip test with hyperjaxb在使用 hyperjaxb 进行往返测试期间忽略数据源
【发布时间】:2012-07-12 14:03:06
【问题描述】:

我正在使用带有 maven 的 Hyperjaxb 3 从 xsd 生成 java 类。为了指定AS中使用的数据源,我使用plugin-configuration(pom.xml)中的persistenceXml设置配置了一个自定义的persistence.xml模板

<configuration>
   <variant>jpa2</variant>
   <persistenceXml>src/main/etc/persistence.xml</persistenceXml>
</configuration>

这是模板:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="2.0">
    <persistence-unit name="##generated">
        <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
</persistence>

由于使用 maven 运行测试时没有数据源,因此往返测试失败。有没有办法忽略jta-data-source 选项并回退到persistence.properties,或者在src/test/resources 中生成替代persistence.xml?

【问题讨论】:

    标签: hibernate jpa-2.0 hyperjaxb


    【解决方案1】:

    是的,正如您所说,使用非容器管理的数据源进行测试是有意义的。您可以在 /src/test/resources 下定义单独的定义(或使用属性文件),并且在运行测试时这应该优先于 src/main/resources 上的定义。

    Junit run not picking file src/test/resources. For file required by some dependency jar

    【讨论】:

    • 这很接近我想要完成的目标。我删除了 persistence.xml 模板并为测试和标准环境添加了一个 hibernate.properties。这对我有用,但缺点是不允许使用标准的 jpa2 连接属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    相关资源
    最近更新 更多