2016-12-01 58 views
0

我正在使用Springboot应用程序使用SqlServer42驱动程序,该应用程序使用jparepositories保存hyperjaxb3生成的实体。使用hyperjaxb3和springboot截断30个字符的SqlServer table/coumn名称

我已改写PhysicalNamingStrategyStandardImpl.toPhysicalTableName()以某些字符串为表名添加前缀。

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

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

另外我检查了sqlserver允许的名字是字符长度。

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

编辑:生成的类被注释为Hyperjaxb这里@Table(name = <Truncated_Value>)

回答

1

作者。

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

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

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

我想你会基本上只需要创建一个“扩展名” JAR与org/jvnet/hyperjaxb3/ejb/plugin/custom/applicationContext.xml文件:

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

+0

感谢您的方向@lexicore。 – Sumit