Closed spring-projects-issues closed 3 years ago
Gerrit Meier commented
Thanks for reporting this. It would be really helpful to get an example that reproduces the error you are facing. Simply creating a domain class and repository with a method you mentioned above does work for me. This is probably not the nicest Kotlin code ever written, but should match what you are targeting:
interface PersonRepository : Neo4jRepository<Person, Long> {
fun findByNameIgnoreCase(label: String): List<Person>
}
@NodeEntity
class Person(var name: String) {
@Id
@GeneratedValue
var id: Long? = null
}
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = [KotlinIntegrationTest.Config::class])
@Transactional
open class KotlinIntegrationTest {
@Autowired
lateinit var repository: PersonRepository
@Test
fun firstKotlinTest() {
val name = "personsName"
val person = Person(name)
repository.save(person)
val result = repository.findByNameIgnoreCase(name)
assertThat(result).hasSize(1)
}
@Configuration
@EnableNeo4jRepositories
@EnableTransactionManagement
internal open class Config {
@Bean
open fun transactionManager(): PlatformTransactionManager {
return Neo4jTransactionManager(sessionFactory())
}
@Bean
open fun sessionFactory(): SessionFactory {
return SessionFactory(
org.neo4j.ogm.config.Configuration.Builder()
.uri("bolt://localhost")
.credentials("neo4j", "neo4j")
.build(),
"org.springframework.data.neo4j.integration.kotlin")
}
}
}
Hi @manuelprinz. I hope this is you. If not, sorry and please ignore the notification.
If you trying to match by the label of a node, this is not gonna work through derived finder methods. You can do this with a custom query around the following idea:
match (n) where any (label IN labels(n) WHERE toLower(label) = 'movie') return n
Here: All nodes that have a label movie
. Of course all string operations, like regex etc, can be applied as well.
For the example @meistermeier added above, find the project attached. I tested it with 5.1.x, 5.2.x and 5.3.x (through Spring Boot 2.1.x, 2.2.x and 2.3.x), works as expected.
Thanks for your contribution.
manuelprinz opened DATAGRAPH-1200 and commented
When creating a repository interface in Kotlin, using
IgnoreCase
will fail with the following error message:This seems to be due to the compiled class being a
kotlin.String
instead ofjava.lang.String
.Using Kotlin strings in
NodeEntities
seems to work fine, so I expected these types of strings being equivalent everywhere.Example:
Please get back to me if you need more information or examples!
Affects: 5.1.5 (Lovelace SR5)