春季JPA在查询方法的字段名称中连续出现两个大写字母时无法定位该字段。

huangapple go评论94阅读模式
英文:

spring jpa not able to locate the field when there are two consecutive capital letter coming in the same field name of a query method

问题

方法名中包含两个连续的大写字母在同一个字段名中时,spring-jpa 无法在表中定位相同的字段。

查询方法示例:

  1. findByTypeAndASiteNameOrTypeAndZSiteName

  2. findByAColumnOrBColumn

以上查询方法解释:

  1. (type AND a_site_name) 或 (type AND z_site_name)
  2. a_column 或 b_column

同样的查询方法在 spring boot 和 spring-data-jpa 的 2.1.7.RELEASE 版本中是正常工作的。目前,我正在迁移到 2.2.5.RELEASE 版本,但我遇到了问题。

异常信息:

无法在此 ManagedType [com.example.h2demo.domain.Subscriber] 上找到具有给定名称 [ASiteName] 的属性。
英文:

When the method name contains two consecutive capital letters in the same field name, the spring-jpa is not able to locate the same field in the table

Examples query method:

1.findByTypeAndASiteNameOrTypeAndZSiteName

2.findByAColumnOrBColumn

The above query method explanation

  1. (type AND a_site_name) or (type AND z_site_name)
  2. a_column or b_column

The same query method was working up to 2.1.7.RELEASE of spring boot and spring-data-jpa. Currently, I am migrating to 2.2.5.RELEASE and I am facing the issue.

Exception:

Unable to locate Attribute with the the given name [ASiteName] on this ManagedType [com.example.h2demo.domain.Subscriber]

答案1

得分: 1

这从Spring Boot 2.1.8变更为2.1.9。

根据Java Beans规范,aColumn的getter和setter必须是:

public String getaColumn()

public void setaColumn(String aColumn)

因此查询方法必须是:

findByaColumnOrbColumn

在Spring Data JPA的JIRA中了解更多信息:
https://jira.spring.io/browse/DATACMNS-1589

英文:

This has changed from Spring Boot 2.1.8 to 2.1.9

According to the Java Beans specification the getter and setter for aColumn must be:

public String getaColumn

public void setaColumn(String aColumn)

So the query method must be:

findByaColumnOrbColumn

Read more about this in the JIRA of Spring Data JPA
https://jira.spring.io/browse/DATACMNS-1589

huangapple
  • 本文由 发表于 2020年4月6日 14:52:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/61054397.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定