Serafeim
Serafeim

Reputation: 15084

Spring data complex query creation

I have created a spring-data-jpa repository to my Student domain model and I want to create a more complex query, something like this:

List findBySchoolAndLastNameLikeOrId(School s);

My problem is how can I define the parentheses between the where clauses. I mean, the query will be executed like this

List findBy(SchoolAndLastNameLike)OrId

or like this

List findBySchoolAnd(LastNameLikeOrId)

And how can I put the parentheses where I want or create even more complex queries? Please don't answer my with custom repository implementations or usage of the @Query annotation - I want to know if what I'd like to do is possible to define this complex query through the method name.

TIA!

Upvotes: 5

Views: 3765

Answers (1)

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83081

In short: you can't. The query derivation mechanism is targeted at simple use cases. For more complex queries, use @Query or define a JPA named query.

Upvotes: 9

Related Questions