findById()找不到属性ID [英] findById() gives No property Id found

查看:666
本文介绍了findById()找不到属性ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个实体. (在此示例中,我使用xxx作为占位符)

I have three entities. (I am using xxx as a place holder for this example)

我已经用

@Entity
@Table(name = "xxx")
public class xxx {

@Id
@Column(name = "xxx_id")
int xxx_id;

但是,我能够做到:

findById(int ...)仅适用于各自存储库中的一个实体. 当我尝试对其他两个实体执行此操作时,出现此问题:

findById(int ...) for only ONE of the entities in their respective Repository. When I try to do that for the other two entities, I get this problem:

无效的派生查询!找不到类型xxx的属性ID!"

"Invalid derived query! No property id found for type xxx!"

我能够运行它并获得适当的结果.但是,为什么我对于两个实体却收到了这个错误,而另一个实体却没有?

I am able to run it and get the proper results. But why am I getting this error for two entities but not the other?

我完全按照相同的方式设置实体及其存储库. 唯一的区别是,在其存储库不返回任何错误的实体中,我将该实体与另一个其存储库发生故障的实体连接在一起,但是在@JoinColumns部分中使用了"mappedBy" .

I set up the entities and their repositories exactly the same way. The ONLY difference is that in the entity whose repository does not return any errors, I am joining that entity with another entity whose repository fails, but I used "mappedBy" in the @JoinColumns section.

这与为什么一个人没有问题有关吗?

Could that have something to do with why that one has no problems?

推荐答案

findBy ...如何工作?

How findBy... works?

Entity:
private int clientid;
private String firstname;
private String lastname;

查询:

Query:

findBy<Name_as_per_entity>
findByClientid(int clientid);
findByFirstnameAndLastname(String firstname, String lastname)

解决方案

由于我们将下划线字符视为保留字符,因此我们 强烈建议您遵循以下标准Java命名约定(即, 而不是在属性名称中使用下划线,而是使用驼峰式大小写.)

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数据查询派生中的 保留字符 ,可能允许手动描述属性路径

The underscore _ is a reserved character in Spring Data query derivation to potentially allow manual property path description.

坚持使用 camel-case 来表示成员变量名称和所有内容的Java命名约定.将按预期工作.

Stick to the Java naming conventions of using camel-case for member variable names and everything will work as expected.

也请参阅此

这篇关于findById()找不到属性ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆