派生查询中的 Spring Data JDBC 列别名被截断
我在 Postgres 11.10 之上使用 Spring Data JDBC 2.0.5(由 Spring Boot 2.3.5 引入)。
在我们的域模型中,我们有一个类似于以下内容的聚合根:
@Table(...)
class OurAggregateRoot {
@MappedColumn(...) // 1:1 relationship
private final ReallyLongClassNameForThisEntity reallyLongClassNameForThisEntity;
}
@Table(...)
class ReallyLongClassNameForThisEntity {
@MappedColumn(really_long_class_name_id) // 1:1 relationship
final AnotherReallyLongClassName anotherReallyLongClassName;
}
鉴于我们有三层关系和长类名,我们遇到了这样的情况:调用 时生成的查询中存在列别名CrudRepository::findById
超出了 PostgreSQL 设置的字符限制。例如,用于引用其父实体的标识符AnotherReallyLongClassName
的列别名将是reallyLongClassNameForThisEntity_anotherReallyLongClassName_really_long_class_name_id
。
除了重命名类/字段/列名称和限制聚合根内的嵌套关系数量之外,我们还能采取什么措施来防止这种情况发生?尝试更改 Postgres 别名的字符限制对我们来说似乎不是一个简单的选择。
I am using Spring Data JDBC 2.0.5 (as pulled in by Spring Boot 2.3.5) on top of Postgres 11.10.
In our domain model we have an aggregate root that looks something like the following:
@Table(...)
class OurAggregateRoot {
@MappedColumn(...) // 1:1 relationship
private final ReallyLongClassNameForThisEntity reallyLongClassNameForThisEntity;
}
@Table(...)
class ReallyLongClassNameForThisEntity {
@MappedColumn(really_long_class_name_id) // 1:1 relationship
final AnotherReallyLongClassName anotherReallyLongClassName;
}
Given that we have three tiers of relationships and long class names we've run into a situation where a column alias in the query that was generated when calling CrudRepository::findById
exceeded the character limit as set by PostgreSQL. E.g. the column alias for the identifier AnotherReallyLongClassName
uses to reference its parent entity would be reallyLongClassNameForThisEntity_anotherReallyLongClassName_really_long_class_name_id
.
Is there something we can do to safeguard against this aside from renaming class/field/column names and limiting the number of nested relationships within an aggregate root? Trying to change the character limit on Postgres alias names doesn't appear to be an easy option for us.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有直接的方法可以避免这种情况。
有用的事情是:正如您所说,为列使用较短的名称,并仔细查看您的聚合:拥有如此深层嵌套的聚合真的合适吗?
There is no direct way to avoid this.
Things that help are: using shorter names for columns as you said and taking a hard look at your aggregates: Is it really appropriate to have such deeply nested aggregates?