How to create priority Queries in JPA Repositories

Viewed 682

I am trying to display a set of records from the database to view page by this query:

findByFirstNameOrSurNameAndGroupG_Name

but it does not work like what I expected! I want it to work like : (findByFirstNameOrSurName)AndGroupG_Name

What is the correct syntax?

1 Answers

Unlike The Comments Given This Is Quite Achievable The Only Downside Is Long Method Names And Repeated Arguments

It's Simple Math, You Can Combine Your Conditions Like This Using Equivalency

A /\ (B \/ C) <=> (A /\ B) \/ (A /\ C)
A and (B or C) <=> (A and B) or (A and C)

And Given The Fact That In Programming Conditions Using And ( && ), First Condition To Meet Has More Priority (In Case Of && If First One Is False Others Are Not Checked And In Case || ( Or ) If First One Is True Others Are Not Checked);

The First Properties You Start Your Method Name With Has More Priority

As The Result Of Things That I Mentioned You Can Achieve What You Want By This Method Name

findByFirstNameAndGroupG_NameOrSurNameAndGroupG_Name(String firstName, String groupName,String firstName2, String groupName2)

I Hope This Is Useful

Comment If You Need Further Help

Related