diff --git a/persistence-modules/spring-data-neo4j/pom.xml b/persistence-modules/spring-data-neo4j/pom.xml index 923d877fd7..bd7d783646 100644 --- a/persistence-modules/spring-data-neo4j/pom.xml +++ b/persistence-modules/spring-data-neo4j/pom.xml @@ -37,18 +37,6 @@ org.springframework.data spring-data-neo4j ${spring-data-neo4j.version} - - - commons-logging - commons-logging - - - - - org.springframework.data - spring-data-neo4j - ${spring-data-neo4j.version} - test-jar com.voodoodyne.jackson.jsog @@ -86,6 +74,11 @@ ${neo4j-ogm.version} test + + org.neo4j + neo4j-ogm-embedded-driver + ${neo4j-ogm.version} + org.neo4j.test neo4j-harness @@ -96,23 +89,17 @@ org.springframework spring-test ${spring-test.version} - - - commons-logging - commons-logging - - - 1.1.1 - 3.1.0 - 4.1.6.RELEASE + 1.6.2 + 3.4.6 + 5.0.1.RELEASE 1.1 - 1.5.13.RELEASE - 4.3.17.RELEASE - 2.1.1 + 2.0.1.RELEASE + 5.0.1.RELEASE + 3.1.2 diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java index 344282d665..9bbc571aee 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java @@ -1,5 +1,6 @@ package com.baeldung.spring.data.neo4j.config; +import org.neo4j.ogm.config.Configuration.Builder; import org.neo4j.ogm.session.SessionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -8,15 +9,14 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; @ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" }) @Configuration -@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory") +@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repository") public class MovieDatabaseNeo4jConfiguration { public static final String URL = System.getenv("NEO4J_URL") != null ? System.getenv("NEO4J_URL") : "http://neo4j:movies@localhost:7474"; @Bean public org.neo4j.ogm.config.Configuration getConfiguration() { - org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); - config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL); + org.neo4j.ogm.config.Configuration config = new Builder().uri(URL).build(); return config; } diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java index fda478e5be..a4cbe4b809 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java @@ -1,26 +1,25 @@ package com.baeldung.spring.data.neo4j.config; +import org.neo4j.ogm.config.Configuration.Builder; import org.neo4j.ogm.session.SessionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.data.neo4j.config.Neo4jConfiguration; import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; +import org.springframework.data.neo4j.transaction.Neo4jTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement @ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" }) -@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory") +@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repository") @Profile({ "embedded", "test" }) -public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration { +public class MovieDatabaseNeo4jTestConfiguration { @Bean public org.neo4j.ogm.config.Configuration getConfiguration() { - final org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); - config.driverConfiguration() - .setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); + org.neo4j.ogm.config.Configuration config = new Builder().build(); return config; } @@ -28,5 +27,10 @@ public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration { public SessionFactory getSessionFactory() { return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain"); } + + @Bean + public Neo4jTransactionManager transactionManager() { + return new Neo4jTransactionManager(getSessionFactory()); + } } diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Car.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Car.java index f2325a334f..455407a92b 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Car.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Car.java @@ -1,12 +1,13 @@ package com.baeldung.spring.data.neo4j.domain; -import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; @NodeEntity public class Car { - @GraphId + @Id @GeneratedValue private Long id; private String make; diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Movie.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Movie.java index 029754c0fc..996a661b07 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Movie.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Movie.java @@ -2,7 +2,9 @@ package com.baeldung.spring.data.neo4j.domain; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.voodoodyne.jackson.jsog.JSOGGenerator; -import org.neo4j.ogm.annotation.GraphId; + +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; @@ -13,7 +15,7 @@ import java.util.List; @NodeEntity public class Movie { - @GraphId + @Id @GeneratedValue Long id; private String title; diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Person.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Person.java index dc5a850f29..453ca1c3f3 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Person.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Person.java @@ -2,7 +2,9 @@ package com.baeldung.spring.data.neo4j.domain; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.voodoodyne.jackson.jsog.JSOGGenerator; -import org.neo4j.ogm.annotation.GraphId; + +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; @@ -11,7 +13,7 @@ import java.util.List; @JsonIdentityInfo(generator = JSOGGenerator.class) @NodeEntity public class Person { - @GraphId + @Id @GeneratedValue Long id; private String name; diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Role.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Role.java index 40dabb054b..5a18837dae 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Role.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/domain/Role.java @@ -3,7 +3,8 @@ package com.baeldung.spring.data.neo4j.domain; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.voodoodyne.jackson.jsog.JSOGGenerator; import org.neo4j.ogm.annotation.EndNode; -import org.neo4j.ogm.annotation.GraphId; +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.RelationshipEntity; import org.neo4j.ogm.annotation.StartNode; @@ -12,8 +13,8 @@ import java.util.Collection; @JsonIdentityInfo(generator = JSOGGenerator.class) @RelationshipEntity(type = "ACTED_IN") public class Role { - @GraphId - Long id; + @Id @GeneratedValue + Long id; private Collection roles; @StartNode private Person person; diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/MovieRepository.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/MovieRepository.java similarity index 78% rename from persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/MovieRepository.java rename to persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/MovieRepository.java index afb82551e7..dde946ea73 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/MovieRepository.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/MovieRepository.java @@ -1,8 +1,8 @@ -package com.baeldung.spring.data.neo4j.repostory; +package com.baeldung.spring.data.neo4j.repository; import com.baeldung.spring.data.neo4j.domain.Movie; import org.springframework.data.neo4j.annotation.Query; -import org.springframework.data.neo4j.repository.GraphRepository; +import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; @Repository -public interface MovieRepository extends GraphRepository { +public interface MovieRepository extends Neo4jRepository { Movie findByTitle(@Param("title") String title); diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/PersonRepository.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/PersonRepository.java new file mode 100644 index 0000000000..22094d26b6 --- /dev/null +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repository/PersonRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.spring.data.neo4j.repository; + +import com.baeldung.spring.data.neo4j.domain.Person; +import org.springframework.data.neo4j.repository.Neo4jRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PersonRepository extends Neo4jRepository { +} diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/PersonRepository.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/PersonRepository.java deleted file mode 100644 index 4ac40ef75b..0000000000 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/repostory/PersonRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.spring.data.neo4j.repostory; - -import com.baeldung.spring.data.neo4j.domain.Person; -import org.springframework.data.neo4j.repository.GraphRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PersonRepository extends GraphRepository { -} diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/services/MovieService.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/services/MovieService.java index ae1f6eb8e5..086bf48bfa 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/services/MovieService.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/services/MovieService.java @@ -1,10 +1,11 @@ package com.baeldung.spring.data.neo4j.services; -import com.baeldung.spring.data.neo4j.repostory.MovieRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.baeldung.spring.data.neo4j.repository.MovieRepository; + import java.util.*; @Service diff --git a/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/neo4j/Neo4jOgmLiveTest.java b/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/neo4j/Neo4jOgmLiveTest.java index 06b31667dd..96e5e76402 100644 --- a/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/neo4j/Neo4jOgmLiveTest.java +++ b/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/neo4j/Neo4jOgmLiveTest.java @@ -12,14 +12,12 @@ import org.neo4j.ogm.session.SessionFactory; import com.baeldung.spring.data.neo4j.domain.Car; import com.baeldung.spring.data.neo4j.domain.Company; -import org.neo4j.ogm.transaction.Transaction; public class Neo4jOgmLiveTest { @Test public void testOgm() { - Configuration conf = new Configuration(); - conf.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); + Configuration conf = new Configuration.Builder().build(); SessionFactory factory = new SessionFactory(conf, "com.baeldung.spring.data.neo4j.domain"); Session session = factory.openSession(); diff --git a/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/spring/data/neo4j/MovieRepositoryIntegrationTest.java b/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/spring/data/neo4j/MovieRepositoryIntegrationTest.java index 95bc38aafc..3d9215f32f 100644 --- a/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/spring/data/neo4j/MovieRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-neo4j/src/test/java/com/baeldung/spring/data/neo4j/MovieRepositoryIntegrationTest.java @@ -4,8 +4,9 @@ import com.baeldung.spring.data.neo4j.config.MovieDatabaseNeo4jTestConfiguration import com.baeldung.spring.data.neo4j.domain.Movie; import com.baeldung.spring.data.neo4j.domain.Person; import com.baeldung.spring.data.neo4j.domain.Role; -import com.baeldung.spring.data.neo4j.repostory.MovieRepository; -import com.baeldung.spring.data.neo4j.repostory.PersonRepository; +import com.baeldung.spring.data.neo4j.repository.MovieRepository; +import com.baeldung.spring.data.neo4j.repository.PersonRepository; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,10 +51,10 @@ public class MovieRepositoryIntegrationTest { Role charlie = new Role(); charlie.setMovie(italianJob); charlie.setPerson(mark); - Collection roleNames = new HashSet(); + Collection roleNames = new HashSet<>(); roleNames.add("Charlie Croker"); charlie.setRoles(roleNames); - List roles = new ArrayList(); + List roles = new ArrayList<>(); roles.add(charlie); italianJob.setRoles(roles); movieRepository.save(italianJob);