The document discusses Spring Data support for non-relational databases (NOSQL) to address challenges of proliferating and complex data not suitable for relational databases. It provides examples of using Spring Data with the Neo4j graph database to model complex domains like social networks by adding graph features to existing JPA data models and handling relationships as entities rather than raw database operations. A new Spring Roo add-on is presented for simplified Neo4j integration.
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
NOSQL part of the SpringOne 2GX 2010 keynote
1. Spring Data NOSQL Support
• Challenge
• Proliferation of data
• Complexity of data
• Won’t all go into relational databases
• NOSQL = Not Only SQL
• Opportunity for Spring to provide solutions
• Spring Data support for new data stores
Column/
Tuesday, October 19, 2010
2. The Neo4j graph database
• A graph database uses nodes, relationships and properties
• Sweet spot: complex domains such as social networking,
bioinformatics, fraud detection, master data mgm
– Very high performance on complex data: traverses 1-2
MILLION hops per second
2
Tuesday, October 19, 2010
3. A scenario ...
You have a traditional web app using JPA to persist data to a
relational database
Tuesday, October 19, 2010
4. Existing JPA data model
Restaurant UserAccount
@Entity @Entity
public class Restaurant { @Table(name = "user_account")
@Id @GeneratedValue public class UserAccount {
private Long id; @Id @GeneratedValue
private String name; private Long id;
private String city; private String userName;
private String state; private String firstName;
private String zipCode; private String lastName;
@Temporal(TemporalType.TIMESTAMP)
private Date birthDate;
@ManyToMany(cascade = CascadeType.ALL)
private Set<Restaurant> favorites;
Tuesday, October 19, 2010
5. Adding Neo4J graph features to the data model
Restaurant UserAccount
@Entity @Entity
@NodeEntity(partial = true) @Table(name = "user_account")
public class Restaurant { @NodeEntity(partial = true)
@Id @GeneratedValue public class UserAccount {
private Long id; @Id @GeneratedValue
private String name; private Long id;
private String city; private String userName;
private String state; private String firstName;
private String zipCode; private String lastName;
@Temporal(TemporalType.TIMESTAMP)
private Date birthDate;
@ManyToMany(cascade = CascadeType.ALL)
Recommendation private Set<Restaurant> favorites;
@RelationshipEntity @GraphProperty
public class Recommendation { String nickname;
@StartNode @RelatedTo(type = "friends",
private UserAccount user; elementClass = UserAccount.class)
@EndNode Set<UserAccount> friends;
private Restaurant restaurant; @RelatedToVia(type = "recommends",
private int stars; elementClass = Recommendation.class)
private String comment; Iterable<Recommendation> recommendations;
Tuesday, October 19, 2010
6. Old style Neo4j code example
public class Recommendation {
private final Relationship underlyingRel;
public Recommendation( Relationship underlyingRel ) {
this.underlyingRel = underlyingRel;
}
public void rate(int stars, String comment) {
this.underlyingRel.setProperty("stars", stars);
this.underlyingRel.setProperty("comment", comment);
}
public int getStars() {
return (Integer) this.underlyingRel.getProperty("stars");
}
public String getComment() {
return (String) this.underlyingRel.getProperty("comment");
}
Tuesday, October 19, 2010
7. New style Spring/Neo4j code example
@RelationshipEntity
public class Recommendation {
@StartNode
private UserAccount user;
@EndNode
private Restaurant restaurant;
private int stars;
private String comment;
public Recommendation() {
}
public void rate(int stars, String comment) {
this.stars = stars;
this.comment = comment;
}
public int getStars() {
return stars;
}
public String getComment() {
return comment;
}
Tuesday, October 19, 2010
10. Conclusion
• The goal of the Spring Data project is to provide simple
and convenient connectivity to non-relational databases
such as Redis, Neo4j, MongoDB and Cassandra
• The Neo4j datastore-graph and Roo add-on have been
developed in collaboration with the Neo4j team
– Already used in a commercial context
• If you want to learn more, go to:
– “Graph Database Persistence using Neo4J with Spring and
Roo” on Friday @ 1015 am
– http://wiki.neo4j.org/content/Neo4j_and_SpringOne
10
Tuesday, October 19, 2010