Database Reference
In-Depth Information
Neo4jTemplate
, as we explained in the beginning of this section, is the con-
venience class that provides methods to perform CRUD operations over the
Neo4j database.
@Autowired
instructs the Spring Framework to automatically
create (or provide reference of the already created Object of Class
Neo4jTem-
plate
) the Object of
Neo4jTemplate
and assign its reference to the given
variable.
Next, using
Neo4jTemplate
, we first persist
Artist
, then
Movie
, and fi-
nally
Role
, which defines the association between
Artist
and
Movie
:
neo4jTemplate.save(artist);
neo4jTemplate.save(rocky);
neo4jTemplate.save(role);
5. Lastly, we need a main class that can bring up our Spring framework and invoke
addData()
. Let's define
org.neo4j.spring.samples
.
MainClass.java
and add following
code:
package org.neo4j.spring.samples;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainClass {
String[] configs = {
"classpath:Application-Config.xml" };
public static void main(String[] args) {
MainClass mainClass = new MainClass();
mainClass.setup();
}
public void setup(){
//Read the Spring configuration file and bring up
the Spring framework, so that all required beans can
be initialized.
ApplicationContext context = new