Hyperjaxb 忽略 binding.xjb 中的自定义

Hyperjaxb ignoring customization in binding.xjb

我正在使用 hyperjaxb3,它成功地解决了我的大部分问题。

但是,我花了整个上午解决一个我无法解决的问题。很可能是我完全忽略的那些愚蠢和愚蠢的事情之一,但我无法找到它。

问题是,在 bindings.xjb 中,我试图更改为我的一个实体生成的 table 名称,但无论我尝试什么,我设置的值都被完全忽略了。

相关文件内容如下:

XSD 文件(只是一个片段)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://.../es/xbrl/eu/model/concept-statement" xmlns:fws="http://.../es/xbrl/eu/model/concept-statement">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>

    <xs:element name="structure">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="fws:module"/>
            </xs:sequence>
        </xs:complexType>
     </xs:element>

bindings.xjb

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
    version="2.1"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    jaxb:extensionBindingPrefixes="hj orm">

    <jaxb:bindings schemaLocation="concept-statement.xsd" node="/xs:schema">
        <jaxb:schemaBindings>
            <jaxb:package name="es.company.cirbe.cubo.hechos.modelo"/>
        </jaxb:schemaBindings>
        <jaxb:globalBindings localScoping="toplevel">
            <jaxb:serializable/>
        </jaxb:globalBindings>
        <jaxb:bindings node="xs:element[@name='structure']">
            <hj:entity>
                <orm:table name="FACTS_STRUCTURE"/>
            </hj:entity>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

pom.xml(仅依赖项和构建部分)

<dependencies>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.2.11</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-ejb-runtime</artifactId>
        <version>0.6.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.hyperjaxb3</groupId>
            <artifactId>maven-hyperjaxb3-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <debug>false</debug>
                <extension>true</extension>
                <variant>ejb</variant>
                <generateDirectory>src/main/java</generateDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/persistence.xml</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

生成了java个文件

@XmlRootElement(name = "structure")
@Entity(name = "Structure")
@Table(name = "STRUCTURE_")
@Inheritance(strategy = InheritanceType.JOINED)
public class Structure
    implements Serializable, Equals, HashCode
{
}

我绝对确定正在读取绑定文件:我已经检查了两个 Maven 日志,如果我为 xpath 表达式设置了一些奇怪的值,我会得到一个与它们相关的运行时异常。

此外,它不仅忽略了 table 名称自定义。我试过更改实体名称、架构、为简单属性设置不同的列长度...在所有这些测试中,输出始终与我在上面复制的相同。

我也检查了现有的样本,但看不出我做错了什么。

此致

好的,找到问题了,它与我的 XSD 文件的结构有关。

正在使用

xs:element[@name='structure']

我的绑定文件还不够。看起来,table 映射自定义仅在与 complexTypes 相关联时才有效,所以一旦我将其更改为

xs:element[@name='structure']/xs:complexType

一切如预期:)

希望这对以后的人有所帮助。