Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-12-2020 09:22 PM
I'm trying to use strong types in my code, e.g. instead of using String in lots of places, using small classes like (Kotlin):
UserId(val value: String)
I'd like to use these all the way down to abstract Repository methods in order to maintain the type-checking benefit, for example:
interface UserRepository : Neo4jRepository<User, Long> {
fun findUserByUserId(userId: UserId)
}
However, when I do something like this, I get the following error:
org.neo4j.driver.exceptions.ClientException: Property values can only be of primitive types or arrays thereof
I had a quick dig through the classes in the stack trace, and I couldn't see anywhere that parameter values are converted in any way at all. (It looks like it would likely be in GraphRepositoryQuery.resolveParams()
if it was anywhere.)
Is there some way to achieve what I'm trying to do?
If not, is it worth adding as a feature request for SDN? (I could possibly even have a crack at implementing it, with some guidance.)
04-12-2020 09:32 PM
Perhaps there's some way to get my types included in the ParameterConversion
used by BoltRequest
?
04-13-2020 10:21 PM
I assume for your constellation there is a lack of functionality in Neo4j-OGM, but I have to check this later this week.
If you really want to use the UserId
as the id for the User
you can also define the repository as <User, UserId>
. This will ensure that you do not have the faulty state of calling findById(Long)
but you can use findById(UserId)
(and also all other methods that are referring to the id).
All that is needed is a @Convert
annotation on the id field with your UserIdTo[String/Long/other neo4j primitive]
converter.
But this will only work after we pulled in this PR (https://github.com/neo4j/neo4j-ogm/pull/788).
04-14-2020 08:48 PM
Thanks for the reply, Gerrit.
The UserID example may have been a bit of a red herring, as the ID isn't the only property that I'm trying to do this for. (And I'm not trying to use it as the ID.)
At any rate, some of the places where I'm trying to use these types rely on custom queries with parameters, so the @Convert on a field solution won't work.
Any ideas on how I could make this work, either with or without changes to neo4j-ogm?
04-15-2020 08:04 AM
I will try to find out if a solution could be to call a globally registered converter (Spring bean) for your type.
All the sessions of the conference are now available online