SqlServer table/coumn 名称被 hyperjaxb3 和 springboot 截断为 30 个字符

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

我将 SqlServer42 驱动程序与 Springboot 应用程序一起使用,该应用程序使用 jparepositories 保存 hyperjaxb3 生成的实体。

我已经覆盖 PhysicalNamingStrategyStandardImpl.toPhysicalTableName() 以在 table 名称前加上一些字符串。

问题是 table 名称和列名称被截断为 30 个字符的限制。最终生成的名称的长度为 30 个字符(前缀 + table 名称)。

即使我不使用前缀并且 table 名称恰好超过 30 个字符,也会被截断。

我还检查了 sqlserver 是否允许名称为 128 字符长度。

有什么方法可以增加此限制,因为 SqlServer 允许超过 30 个字符名称。

编辑:生成的 类 用 @Table(name = <Truncated_Value>)

注释

这里是 Hyperjaxb 的作者。

HJ3 尝试生成尽可能跨数据库兼容的注释。 30 个字符的截断来自 Oracle。

目前default naming strategy中是"hardcoded"。无法 "easily" 重新配置它(即通过插件配置选项或类似方式)。唯一的选择似乎是编写您自己的命名策略或记录默认命名策略。这是一个演示如何执行此操作的测试项目:

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

我认为您基本上只需要使用 org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml 文件创建一个 "extension" JAR:

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

然后将此工件添加到 HJ3 插件的类路径中。 For example,在 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>

这将覆盖 default naming configuration