Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-07-2022 08:42 AM
I am thinking about giving SDN a go again, trying out Interface-based Projections:
interface UserSDNRepository : ReactiveNeo4jRepository<UserSDN, Long> {
fun findAllUsernames(): Flux<UsernameOnly>
}
interface UsernameOnly {
val username: String?
}
and also tried a Java interface like
public interface UsernameOnly{
String getUsername();
}
but as soon as Spring Boot starts up I get:
...
Caused by: org.springframework.data.mapping.PropertyReferenceException:
No property 'findAllUsernames' found for type 'UserSDN'!
...
I have tried different names for the findAll function.
BTW I also have a fun findByUsername(username: String): Mono<SimpleUser>
where SimpleUser is a class based projection and that works fine.
What am I missing here? I think according to the docs at Spring Data Neo4j that should work. Is it not possible with Reactive repositories? Or is it a Kotlin issue?
Cheers, Chris
04-12-2022 12:01 AM
This is not a problem with projections but the query method you are defining.
The fun findByUsername(username: String): Mono<SimpleUser>
works because you are looking for the username
field in the entity UserSDN
.
The other query method defines a findAll_Usernames_
. This will make SDN look into UserSDN
for the property usernames
(plural). The error message gives the hint that it cannot find this particular property.
Back to your use-case:
If you do not want to use the property, you could write fun findAllProjectedBy(): Flux<UsernameOnly>
.
What you could also do, is to write a generic projection method like this:
fun <T> findAllProjectedBy(projectionClass: Class<T>): List<T>
This would allow you to use different projection if needed.
04-15-2022 01:33 PM
Thanks for the reply, Gerrit!
All the sessions of the conference are now available online