sql-serverhibernatesql-server-2008spring-boothyperjaxb

SqlServer table/coumn name truncated to 30 characters with hyperjaxb3 and springboot


I am using SqlServer42 driver with a Springboot application which is saving hyperjaxb3 generated entities using jparepositories.

I have overridden PhysicalNamingStrategyStandardImpl.toPhysicalTableName() to prefix the table names with some string.

The problem is that the table names and the column names are truncated to 30 char limit. The final generated names are of 30 char length (prefix + tablename).

Even if I do not use the prefix and the table name happens to be of more than 30 char, the same is truncated.

Also I checked that sqlserver allows names to be of 128 char length.

Is there any way to increase this limit as SqlServer does allow more than 30 char names.

Edit : The generated classes are annotated with @Table(name = <Truncated_Value>)


Solution

  • Author of Hyperjaxb here.

    HJ3 tries to generate as cross-database-compatible annotations as possible. The truncation for 30 characters comes from Oracle.

    At the moment, it is "hardcoded" in the default naming strategy. There is no way of "easily" reconfiguring this (i.e. via plugin configuration options or similar). The only option seems to be to write your own naming strategy or recordingure the default naming strategy. Here's a test project which demonstrates how to do this:

    https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/custom-naming

    I think you will basically just need to create an "extension" JAR with the org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml file:

    <?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="org.jvnet.hyperjaxb3.ejb.strategy.naming.impl.DefaultNaming">
            <property name="reservedNames" ref="reservedNames"/>
            <property name="ignoring" ref="ignoring"/>
            <property name="maxIdentifierLength" value="128"/>
        </bean>
    
    </beans>
    

    Then you add this artifact into the classpath of the HJ3 plugin. For example, in Maven:

    <build>
        <defaultGoal>test</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.jvnet.hyperjaxb3</groupId>
                <artifactId>maven-hyperjaxb3-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.jvnet.hyperjaxb3</groupId>
                        <artifactId>hyperjaxb3-ejb-tests-custom-naming-extension</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    

    This will override the default naming configuration.