Closed Kanish2002 closed 10 months ago
@Node
class StrategyStarter : StrategyNode(){
@Required
@Unique
var strategyName: String? = null
}
Hello sir this is my code, and I created two instances of StrategyStarter
val strategyStarter = StrategyStarter("a")
val strategyStarter1 = StrategyStarter("a")
neo4jTemplate.saveAll(listOf(strategyStarter,strategyStarter1))
OPTIONAL MATCH (hlp:`StrategyStarter`) WHERE hlp.id = $__id__ WITH hlp WHERE hlp IS NULL CREATE (strategyStarter:`StrategyStarter`) WITH strategyStarter SET strategyStarter += $__properties__ RETURN strategyStarter UNION MATCH (strategyStarter:`StrategyStarter`) WHERE strategyStarter.id = $__id__ WITH strategyStarter SET strategyStarter += $__properties__ RETURN strategyStarter
2023-12-01T17:20:43.894+05:30 DEBUG 1242869 --- [ main] org.springframework.data.neo4j.cypher : Executing:
OPTIONAL MATCH (hlp:`StrategyStarter`) WHERE hlp.id = $__id__ WITH hlp WHERE hlp IS NULL CREATE (strategyStarter:`StrategyStarter`) WITH strategyStarter SET strategyStarter += $__properties__ RETURN strategyStarter UNION MATCH (strategyStarter:`StrategyStarter`) WHERE strategyStarter.id = $__id__ WITH strategyStarter SET strategyStarter += $__properties__ RETURN strategyStarter
2023-12-01T17:20:44.064+05:30 WARN 1242869 --- [ main] .s.n.m.s.b.a.MigrationsAutoConfiguration : No package to scan is configured and none of the configured locations exists.
2023-12-01T17:20:44.281+05:30 INFO 1242869 --- [ main] a.s.n.m.core.Migrations.Startup : neo4j-migrations/2.7.0 connected to
neo4j@localhost:7687 (Neo4j/5.3.0 Enterprise Edition)
Database: neo4j
2023-12-01T17:20:44.638+05:30 INFO 1242869 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
2023-12-01T17:20:44.641+05:30 INFO 1242869 --- [ main] c.z.strategy.StrategyApplicationKt : Started StrategyApplicationKt in 1.966 seconds (process running for 2.166)
Still 2 nodes with same name is created
implementation("eu.michael-simons.neo4j:neo4j-migrations-spring-boot-starter:2.7.0")
implementation("eu.michael-simons.neo4j:neo4j-migrations-annotation-catalog:2.7.0")
above are the groups I use in my build.gradle.kts
in a SpringBoot Project
Is there anything I'm doing in a wrong way?
Please guide me with the above information.
I think you should read up on the concept:
dependencies {
annotationProcessor 'eu.michael-simons.neo4j:neo4j-migrations-annotation-processor'
// Plus the starter and the dependency for the catalog on implementation
}
This will generate Cypher scripts for you, containing the necessary constraint definitions. Those must be applied to your database, all the checks will be done in the database.
Neo4j-Migrations will do this for you if you configure the paths correctly. For that, see the docs or the example in here:
I am not a Gradle person, but I think it should not be too hard to translate this.
In the example test I'm using the SDN annotations alone (See https://github.com/michael-simons/neo4j-migrations/blob/main/neo4j-migrations-examples/neo4j-migrations-examples-sb/src/main/java/ac/simons/neo4j/migrations/examples/sb/Person.java), but that will also generate me a unique constraint for the generated id.
This is not a bug, therefor I did close this.
You can just use the annotations. It’s is described here https://michael-simons.github.io/neo4j-migrations/2.7.0/#appendix_annotation look for the headline “additional annotations”