Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用实体查询,框架会拼接字段名称为【表别名_字段】而遭到 ColumnNameChecker 字段名称过长拦截 #566

Open
canmengqian opened this issue Jul 3, 2024 · 6 comments

Comments

@canmengqian
Copy link

通过元数据里的maxColumnNameLength 和拼接后的字段 来进行比较长度,导致因为拼接了表别名的原因遭到ColumnNameChecker 拦截

image

image

image

@canmengqian canmengqian changed the title 使用实体查询,使用拼接后的字段【表别名_字段】遭到 ColumnNameChecker 字段名称过长拦截 使用实体查询,框架会拼接字段名称为【表别名_字段】而遭到 ColumnNameChecker 字段名称过长拦截 Jul 3, 2024
@vincentlauvlwj
Copy link
Member

alias 短一点,单字母就可以,30 个字符的长度够用了

@canmengqian
Copy link
Author

@vincentlauvlwj 目前项目里有些列名已经接近30个字符,拼上表别名就超了 😂😂😂

@vincentlauvlwj
Copy link
Member

@canmengqian 你用的是什么数据库,一般数据库的长度限制都是 64 左右,30 比较少见

@vincentlauvlwj
Copy link
Member

@vincentlauvlwj 目前项目里有些列名已经接近30个字符,拼上表别名就超了 😂😂😂

那也没办法,只能精简一下字段名,这里不校验的话,有些数据库会把超出长度的名字截断,会导致更隐蔽的 bug

@canmengqian
Copy link
Author

@vincentlauvlwj 用的Oracle数据库,是不是可以考虑不用将表别名纳入校验范围内,或者可以提供卸载拦截器的方式,或加上自定义拦截器接口

@vincentlauvlwj
Copy link
Member

如果你能承担字段名截断的风险,可以用这个办法绕过校验

val database = Database.connect { ConnectionWrapper(dataSource.connection) }

class ConnectionWrapper(private val connection: Connection) : Connection by connection {

    override fun getMetaData(): DatabaseMetaData {
        return DatabaseMetaDataWrapper(connection.metaData)
    }
}

class DatabaseMetaDataWrapper(private val databaseMetaData: DatabaseMetaData) : DatabaseMetaData by databaseMetaData {

    override fun getMaxColumnNameLength(): Int {
        return 0
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants