Search code examples
jpajaxbhyperjaxb

Hyperjaxb ignoring customization in binding.xjb


I'm using hyperjaxb3 and it's solving most of my issues successfully.

However, I've spent the whole morning with a problem that I'm not able to solve. Most probably, is one of those silly and stupid things that I'm completely overlooking, but I'm unable to locate it.

Problem is that, inside bindings.xjb I'm trying to change the generated table name for one of my entities, but no matter what I try, the value I set is completely ignored.

These are the contents of the related files:

XSD file (just a snippet)

<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 (just dependencies and build part)

<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>

Generated java file

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

I'm absolutely sure that the bindings file is being read: I've checked both maven log and, if I set some weird values to the xpath expressions, I get a runtime exception related to them.

Also, it is not only ignoring the table name customization. I've tried changing the entity name, the schema, setting a different column length for a simple attribute... In all those tests the output was always the same I copied above.

And I've also checked the existing samples, but couldn't see what I'm doing wrong.

Regards


Solution

  • Ok, found the issue and it was related to the structure of my XSD file.

    Just using

    xs:element[@name='structure']
    

    on my bindings file was not enough. As it seems, the table mappings customization only work when associated with complexTypes, so as soon as I changed that to

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

    everything worked as expected :)

    Hope this will help someone in the future.