【问题标题】:SqlServer table/coumn name truncated to 30 characters with hyperjaxb3 and springboot使用 hyperjaxb3 和 springboot 将 SqlServer 表/列名截断为 30 个字符
【发布时间】:2017-04-15 18:03:54
【问题描述】:

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

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

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

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

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

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

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

【问题讨论】:

    标签: sql-server hibernate sql-server-2008 spring-boot hyperjaxb


    【解决方案1】:

    Hyperjaxb 的作者在这里。

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

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

    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 插件的类路径中。 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

    【讨论】:

    • 感谢@lexicore 的指导。
    猜你喜欢
    • 2016-10-14
    • 2012-11-03
    • 2023-03-07
    • 2019-12-01
    • 1970-01-01
    • 2012-03-07
    • 2019-03-03
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多