Skip to content
Advertisement

Spring Data JPA: FindBy on Join Column

I have setup two entities like below in a one-to-one mapping and I am trying to query on the joincolumn like below in my repository:

JavaScript

In my BRepository.java, I am trying to do this:

JavaScript

I get the following error:

No property a found for type B! Did you mean 'aId'?

Is this not the right way to query on a join column in spring-data??

Advertisement

Answer

Since you have not defined the column name for id in A then the column name will defaults to id. Then in class B, you should change the referencedColumnName to id (or else you can simply skip the referencedColumnName attribute since it can be derived directly from the target entity in an OneToOne relationship)

JavaScript

In repository, you need to annotate it with @Repository annotation to let Spring know it should be treated as a Repository Bean.

JavaScript

or you can use SPeL directly,

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement