@@ -3554,7 +3554,7 @@ considered. A typical entity class resembles the following example:
3554
3554
3555
3555
public City(String name, String state) {
3556
3556
this.name = name;
3557
- this.country = country ;
3557
+ this.state = state ;
3558
3558
}
3559
3559
3560
3560
public String getName() {
@@ -3606,7 +3606,7 @@ The following example shows a typical Spring Data repository interface definitio
3606
3606
3607
3607
Page<City> findAll(Pageable pageable);
3608
3608
3609
- City findByNameAndCountryAllIgnoringCase (String name, String country );
3609
+ City findByNameAndStateAllIgnoringCase (String name, String state );
3610
3610
3611
3611
}
3612
3612
----
@@ -4006,7 +4006,7 @@ in the following example:
4006
4006
4007
4007
Page<City> findAll(Pageable pageable);
4008
4008
4009
- City findByNameAndCountryAllIgnoringCase (String name, String country );
4009
+ City findByNameAndStateAllIgnoringCase (String name, String state );
4010
4010
4011
4011
}
4012
4012
----
@@ -4045,78 +4045,85 @@ the Mongo instance's configuration and logging routing.
4045
4045
[[boot-features-neo4j]]
4046
4046
=== Neo4j
4047
4047
http://neo4j.com/[Neo4j] is an open-source NoSQL graph database that uses a rich data
4048
- model of nodes related by first class relationships, which is better suited for connected
4049
- big data than traditional rdbms approaches. Spring Boot offers several conveniences for
4050
- working with Neo4j, including the `spring-boot-starter-data-neo4j` "`Starter`".
4048
+ model of nodes connected by first class relationships, which is better suited for
4049
+ connected big data than traditional RDBMS approaches. Spring Boot offers several
4050
+ conveniences for working with Neo4j, including the `spring-boot-starter-data-neo4j`
4051
+ "`Starter`".
4051
4052
4052
4053
4053
4054
4054
4055
[[boot-features-connecting-to-neo4j]]
4055
4056
==== Connecting to a Neo4j Database
4056
- You can inject an auto-configured `Neo4jSession`, `Session`, or `Neo4jOperations`
4057
- instance as you would any other Spring Bean. By default, the instance tries to connect to
4058
- a Neo4j server at `localhost:7474` . The following example shows how to inject a Neo4j
4059
- bean :
4057
+ To access a Neo4j server, you can inject an auto-configured
4058
+ `org.neo4j.ogm.session.Session`. By default, the instance tries to connect to a Neo4j
4059
+ server at `localhost:7687` using the Bolt protocol . The following example shows how to
4060
+ inject a Neo4j `Session` :
4060
4061
4061
4062
[source,java,indent=0]
4062
4063
----
4063
4064
@Component
4064
4065
public class MyBean {
4065
4066
4066
- private final Neo4jTemplate neo4jTemplate ;
4067
+ private final Session session ;
4067
4068
4068
4069
@Autowired
4069
- public MyBean(Neo4jTemplate neo4jTemplate ) {
4070
- this.neo4jTemplate = neo4jTemplate ;
4070
+ public MyBean(Session session ) {
4071
+ this.session = session ;
4071
4072
}
4072
4073
4073
4074
// ...
4074
4075
4075
4076
}
4076
4077
----
4077
4078
4078
- You can take full control of the configuration by adding a
4079
- `org.neo4j.ogm.config.Configuration` `@Bean` of your own. Also, adding a `@Bean` of type
4080
- `Neo4jOperations` disables the auto-configuration.
4081
-
4082
- You can configure the user and credentials to use by setting the `spring.data.neo4j.*`
4079
+ You can configure the uri and credentials to use by setting the `spring.data.neo4j.*`
4083
4080
properties, as shown in the following example:
4084
4081
4085
4082
[source,properties,indent=0]
4086
4083
----
4087
- spring.data.neo4j.uri=http ://my-server:7474
4084
+ spring.data.neo4j.uri=bolt ://my-server:7687
4088
4085
spring.data.neo4j.username=neo4j
4089
4086
spring.data.neo4j.password=secret
4090
4087
----
4091
4088
4089
+ You can take full control over the session creation by adding a
4090
+ `org.neo4j.ogm.config.Configuration` `@Bean`. Also, adding a `@Bean` of type
4091
+ `SessionFactory` disables the auto-configuration and gives you full control.
4092
+
4092
4093
4093
4094
4094
4095
[[boot-features-connecting-to-neo4j-embedded]]
4095
4096
==== Using the Embedded Mode
4096
-
4097
4097
If you add `org.neo4j:neo4j-ogm-embedded-driver` to the dependencies of your application,
4098
4098
Spring Boot automatically configures an in-process embedded instance of Neo4j that does
4099
- not persist any data when your application shuts down. You can explicitly disable that
4100
- mode by setting `spring.data.neo4j.embedded.enabled=false`. You can also enable
4101
- persistence for the embedded mode by providing a path to a database file, as shown in the
4102
- following example:
4099
+ not persist any data when your application shuts down.
4103
4100
4104
- ----
4105
- spring.data.neo4j.uri=file://var/tmp/graph.db
4106
- ----
4101
+ [NOTE]
4102
+ ====
4103
+ As the embedded Neo4j OGM driver does not provide the Neo4j kernel itself, you have
4104
+ to declare `org.neo4j:neo4j` as dependency yourself. Refer to
4105
+ https://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started[the
4106
+ Neo4j OGM documentation] for a list of compatible versions.
4107
+ ====
4108
+
4109
+ The embedded driver takes precedence over the other drivers when there are multiple
4110
+ drivers on the classpath. You can explicitly disable the embedded mode by setting
4111
+ `spring.data.neo4j.embedded.enabled=false`.
4112
+
4113
+ <<boot-features-testing-spring-boot-applications-testing-autoconfigured-neo4j-test,Data Neo4j Tests>>
4114
+ automatically make use of an embedded Neo4j instance if the embedded driver and Neo4j
4115
+ kernel are on the classpath as described above.
4107
4116
4108
4117
[NOTE]
4109
4118
====
4110
- The Neo4j OGM embedded driver does not provide the Neo4j kernel. Users are expected to
4111
- provide this dependency manually. See
4112
- http://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started[the
4113
- documentation] for more details.
4119
+ You can enable persistence for the embedded mode by providing a path to a database file
4120
+ in your configuration, e.g. `spring.data.neo4j.uri=file://var/tmp/graph.db`.
4114
4121
====
4115
4122
4116
4123
4124
+
4117
4125
[[boot-features-neo4j-ogm-session]]
4118
4126
==== Neo4jSession
4119
-
4120
4127
By default, if you are running a web application, the session is bound to the thread for
4121
4128
the entire processing of the request (that is, it uses the "Open Session in View"
4122
4129
pattern). If you do not want this behavior, add the following line to your
@@ -4133,42 +4140,32 @@ pattern). If you do not want this behavior, add the following line to your
4133
4140
==== Spring Data Neo4j Repositories
4134
4141
Spring Data includes repository support for Neo4j.
4135
4142
4136
- In fact, both Spring Data JPA and Spring Data Neo4j share the same common infrastructure.
4137
- You could take the JPA example from earlier and, assuming that `City` is now a Neo4j OGM
4138
- `@NodeEntity` rather than a JPA `@Entity`, it works in the same way.
4139
-
4140
- TIP: You can customize entity scanning locations by using the `@EntityScan` annotation.
4141
-
4142
- To enable repository support (and optionally support for `@Transactional`), add the
4143
- following two annotations to your Spring configuration:
4144
-
4145
- [source,java,indent=0]
4146
- ----
4147
- @EnableNeo4jRepositories(basePackages = "com.example.myapp.repository")
4148
- @EnableTransactionManagement
4149
- ----
4150
-
4151
- ==== Repository Example
4152
-
4153
- The following example shows an interface definition for a Neo4j repository:
4143
+ Spring Data Neo4j shares the common infrastructure with Spring Data JPA as many other
4144
+ Spring Data modules do. You could take the JPA example from earlier and define
4145
+ `City` as Neo4j OGM `@NodeEntity` rather than JPA `@Entity` and the repository
4146
+ abstraction works in the same way, as shown in the following example:
4154
4147
4155
4148
[source,java,indent=0]
4156
4149
----
4157
4150
package com.example.myapp.domain;
4158
4151
4159
- import org.springframework.data.domain.*;
4160
- import org.springframework.data.repository.*;
4152
+ import java.util.Optional;
4161
4153
4162
- public interface CityRepository extends GraphRepository<City> {
4154
+ import org.springframework.data.neo4j.repository.*;
4163
4155
4164
- Page <City> findAll(Pageable pageable);
4156
+ public interface CityRepository extends Neo4jRepository <City, Long> {
4165
4157
4166
- City findByNameAndCountry (String name, String country );
4158
+ Optional< City> findOneByNameAndState (String name, String state );
4167
4159
4168
4160
}
4169
4161
----
4170
4162
4171
- TIP: For complete details of Spring Data Neo4j, including its rich object mapping
4163
+ The `spring-boot-starter-data-neo4j` "`Starter`" enables the repository support as well
4164
+ as transaction management. You can customize the locations to look for repositories and
4165
+ entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively on a
4166
+ `@Configuration`-bean.
4167
+
4168
+ TIP: For complete details of Spring Data Neo4j, including its object mapping
4172
4169
technologies, refer to the https://projects.spring.io/spring-data-neo4j/[reference
4173
4170
documentation].
4174
4171
0 commit comments