派生查询中的 Spring Data JDBC 列别名被截断

发布于 2025-01-15 01:58:22 字数 954 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧故 2025-01-22 01:58:22

没有直接的方法可以避免这种情况。
有用的事情是:正如您所说,为列使用较短的名称,并仔细查看您的聚合:拥有如此深层嵌套的聚合真的合适吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文