I have the following query:
@Query("select c.status from Component c where c.id = ?1")
ComponentStatus findStatusByComponentId(ComponentId id);
Why IntelliJ
is warning me with: 'Component' domain type or valid projection interface expected here?
Any one can help me?
Any Spring data repository method that takes the form " find.*By.+
" (eg " find<DOMAIN_TYPE>By<PROJECTION_INTERFACE>
" or " findBy<PROJECTION_INTERFACE>
") is going to give that warning if it doesn't match a valid derived query. If you start typing "find" and wait for the autocomplete dialog box, it will suggest some of the derived query methods (or at least, the start of them).
If you continue typing a valid domain type (in my case, RequestSampleTest) the autocomplete box will continue updating with more possibilities (there are a LOT of possible derived queries, depending on the Entity).
This article ( https://www.baeldung.com/spring-data-derived-queries ) gives a really good introduction to Spring data derived queries. They're basically a streamlined way to perform basic search and sort queries.
As a note to your comment: By adding an 'x' in front of the method name, it no longer "looks like" a derived query, so the warning goes away.
Also of note: I think only IntelliJ Pro edition provides Spring support, so if you're not seeing those dropdowns, it might be because you're on Community Edition.
Probably because it go against the pattern that Spring Data is expects. And you can do that query (something) like this:
ComponentStatus findStatusById(ComponentId id);
You don't need to write the query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.