Database Reference
In-Depth Information
rocky.setYear(1976);
rocky.setId(rocky.getTitle()
+"-"+String.valueOf(rocky.getYear()));
// Create Artists
Artist artist = new Artist();
artist.setName("Sylvester Stallone");
artist.setWorkedAs(new String[] { "Actor",
"Director" });
artist.setYear_Of_Birth(1946);
artist.setId(artist.getName()
+"-"+artist.getYear_Of_Birth());
// create Relationship
Role role = new Role(artist, rocky, "Rocky Balboa");
neo4jTemplate.save(artist);
neo4jTemplate.save(rocky);
neo4jTemplate.save(role);
}
}
In the preceding code, we have defined the
addData()
method, which creates
the object of
Movie
and
Artist
, provides appropriate values to its properties,
and then defines an Object of
Role
, which further defines the relationship
between
Artist
and
Movie
. The
addData()
method is annotated with
@Transactional
, which will inform the Spring framework to start a new
transaction while executing this method.
Easy and clean isn't it?
We have only written the business logic; all the boilerplate code such as wrapping
your Neo4j code within a transaction will be handled by the framework.
The interesting part is the declaration of:
@Autowired
private Neo4jTemplate neo4jTemplate;