how to get records from DB on multiple conditions?
hey guys. so i have this repo class:
So i want to be able to get records where season in db is the same as in the request AND get all records from the where season is
all
. and also combine with db records, where db records has less or equal distance than distance in the request. is it possible? how can i do that?7 Replies
⌛
This post has been reserved for your question.
Hey @bambyzas! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
i would just write a
@Query
: https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html#jpa.query-methods.at-queryoh, okay. didnt know thats possible.
if i have
@Query(nativeQuery = true,value = "SELECT name FROM items WHERE distance<=?1 AND season IN (?2, 'all')")
, and do a request, i get
but if i do select * ...
it works. but i dont want to select all the columns. what can i do?you can just do @Query("[insert JPA query here]") not a native query
unless if you actually want to run a native query of course
jqpl queries make no sense to me. their syntax are too complicated for me
the JPA version of your query i think would be:
well the full method would be:
i don't think it's too different from your native query:
* replaced
name
with i
in the select
* referring to the JPA entity name Item
in the from
* using dot notation to access the members in the where
e.g. (i.season
instead of just season
)💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.