我有三个实体。 (我使用 xxx 作为这个例子的占位符)
我已经设置了他们所有的 @Entities
与
@Entity
@Table(name = "xxx")
public class xxx {
@Id
@Column(name = "xxx_id")
int xxx_id;
但是,我能够做到:
findById(int ...)
仅适用于其各自存储库中的一个实体。
当我尝试为其他两个实体执行此操作时,我遇到了这个问题:
"Invalid derived query! No property id found for type xxx!"
我能够运行它并获得正确的结果。但为什么我会为两个实体收到此错误,而另一个却没有?
我以完全相同的方式设置实体及其存储库。
唯一的区别是,在存储库未返回任何错误的实体中,我将该实体与另一个存储库失败的实体连接在一起,但我在 @JoinColumns
中使用了 “mappedBy”部分。
这与为什么没有问题有关吗?
最佳答案
findBy... 是如何工作的?
Entity:
private int clientid;
private String firstname;
private String lastname;
查询:
findBy<Name_as_per_entity>
findByClientid(int clientid);
findByFirstnameAndLastname(String firstname, String lastname)
解决方案
Because we treat the underscore character as a reserved character, we strongly advise following standard Java naming conventions (that is, not using underscores in property names but using camel case instead).
下划线 _ 是 Spring Data 查询派生中的保留字符,可能允许手动属性路径描述.
坚持使用 camel-case 的 Java 命名约定对于成员变量名称,一切都会按预期工作。
关于spring - findById() 给出未找到属性 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56961166/