Skip to content
Advertisement

How to use part of composite key in JPA repository methods?

I have a class with embedded Id

JavaScript

Now in my repository I want to have a method to search only by secAccount, so how should I write findBy..

JavaScript

I tried findByAccountLinkKeySecAccount(String secAccount) but still no success.

Advertisement

Answer

I have rewritten your class and could add repository function as well. Here’s my implementation which you might consider taking a look at.

Here’s the class AccountLink.java.

JavaScript

And the AccountLinkRepository.java.

JavaScript

I have added an id column in the AccountLink class as the primary key of the account_table. You might need something like this as well for your table.

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