1

We have a significant code base that utilizes Hyperjaxb3 to annotate Java classes that are generated using xjc (along with other xjc plugins, including one that is home-grown).

We are in the process of trying to upgrade from Hyperjaxb3 0.5.6 to 0.6.2, but have run into a significant issue with an apparent naming strategy change between these versions.

Specifically, where a complexType name like "OneTwo" results in a table name "ONETWO" in 0.5.6, whereas in 0.6.2 the table name is "ONE_TWO". Same for column names.

We have a very strong preference to NOT refactor hundreds of queries to accommodate such a naming change (although the newer, more traditional SQL naming certainly makes sense - we wish it had been the default behavior when this project started six years ago).

Is there an easy way to switch to the old naming strategy? Failing that, can you provide details on exactly how to extend Hyperjaxb3 with a custom naming strategy?

Having looked at this test or this one, it is not clear to us exactly what we need to do to our pom to specify a different naming strategy class, and the Extension Guide is currently empty.

  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
      <extension>true</extension>
      <plugins>
        <plugin>
          <groupId>org.jvnet.jaxb2_commons</groupId>
          <artifactId>jaxb2-basics</artifactId>
          <version>${jaxb.commons.version}</version>
        </plugin>
        <plugin>
          <groupId>org.jvnet.hyperjaxb3</groupId>
          <artifactId>hyperjaxb3-ejb-plugin</artifactId>
          <version>${hyperjaxb3.version}</version>
        </plugin>
        <plugin>
          <groupId>${project.groupId}</groupId>
          <artifactId>jaxb-x12</artifactId>
          <version>${project.version}</version>
        </plugin>
      </plugins>
      <args>
        <arg>-enableIntrospection</arg>
        <arg>-Xcopyable</arg>
        <arg>-Xequals</arg>
        <arg>-XhashCode</arg>
        <arg>-Xinheritance</arg>
        <arg>-Xhyperjaxb3-ejb</arg>
        <arg>-Xx12</arg>
      </args>
    </configuration>
  </plugin>
Rob
  • 6,247
  • 2
  • 25
  • 33

1 Answers1

1

Author of HJ3 here.

Take a look at thes custom-naming test project. It implements and configures a custom naming strategy.

The solution consists of two parts: implementation of the naming strategy and configuration of this implementation.

You naming implementation must implement the org.jvnet.hyperjaxb3.ejb.strategy.naming.Naming interface. The easiest would be to inherit from org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming.

To configure you have to create a resource /org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml which is basically a Spring XML configuration. There, define a bean with the name naming:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean name="naming" class="com.acme.foo.MyNaming">
        <property name="reservedNames" ref="reservedNames"/>
    </bean>

</beans>

This will overwrite the standard naming strategy.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • I have the exact same problem. Tried to replicate the structure of the custom-naming test project and all but it looks that the generated entities are not affected. Is there any way to make sure that the custom naming class is actually being called? – Arch Nov 07 '19 at 17:03
  • @Arch Throw an exception an see if it is actually thrown. – lexicore Nov 09 '19 at 17:20
  • Hi @lexicore, i have actually done that but no luck. Combining your answers from different questions here on SO I got to the point where I have created a tiny project (based on the github examples) containing the Class that overrides the naming strategy and the spring xml bean in the resources. I have checked that the xml is included in the produced jar and used that jar as a dependency in the project where I try to generate entities from an XSD using the maven plugin. Unfortunately nothing happens. – Arch Nov 11 '19 at 12:04
  • @Arch Send me a PR with a sample project somewhere under https://github.com/highsource/hyperjaxb3-support. I'll take a look what the problem might be. – lexicore Nov 11 '19 at 20:14