0

我正在使用带有 Springboot 应用程序的 SqlServer42 驱动程序,该应用程序使用 jparepositories 保存 hyperjaxb3 生成的实体。

我已经PhysicalNamingStrategyStandardImpl.toPhysicalTableName()用一些字符串覆盖了表名的前缀。

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

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

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

有没有办法增加这个限制,因为 SqlServer 确实允许超过 30 个字符名称。

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

4

1 回答 1

1

Hyperjaxb的作者在这里。

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

目前,它在默认命名策略中是“硬编码”的。没有办法“轻松”重新配置它(即通过插件配置选项或类似的)。唯一的选择似乎是编写自己的命名策略或记录默认命名策略。这是一个演示如何执行此操作的测试项目:

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

我认为您基本上只需要使用该org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml文件创建一个“扩展”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 插件的类路径中。例如,在 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>

这将覆盖默认命名配置

于 2016-12-02T08:16:28.023 回答