Anton Kolosok
Anton Kolosok

Reputation: 522

Spring Data find by column that is not in entity

I have two entities

1)

Person

int id
String name

@JoinColumn(name = "person_id")
List<Email> emailList;

2)

Email

int id
String emailAddress

In Email table, I have three columns - id, emailAddress, person_id.

My question is - can I write a SpringData method in EmailRepository like - findByEmailAddressAndPersonIdNotNull(String emailAddress)

or do I have to write a custom @Query?

I need to find email by column person_id.

Upvotes: 0

Views: 414

Answers (1)

Jens Schauder
Jens Schauder

Reputation: 81882

findByEmailListEmailAddressAndPersonIdNotNull(String emailAddress) or findByEmailList_EmailAddressAndPersonIdNotNull(String emailAddress)

should work.

Upvotes: 1

Related Questions