I have created a Maven project using spring-data-neo4j. I have also installed the standalone Neo4j Server Community Edition 2.3.3. I am trying to save some Vertex objects to the database and then simply retrieve them to check everything works fine. Then, I would like to be able to open the created db in the standalone server for better visualization. I am using as dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
The configuration class is:
@Configuration
@ComponentScan("neo4j.example")
@EnableAutoConfiguration
@EnableNeo4jRepositories("neo4j.example.repository")
public class App extends Neo4jConfiguration {
public App() {
System.setProperty("username", "neo4j");
System.setProperty("password", "root");
}
@Override
public SessionFactory getSessionFactory() {
return new SessionFactory("neo4j.example.model");
}
@Override
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
@Override
public Neo4jServer neo4jServer() {
return new RemoteServer("http://localhost:7474");
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
My NodeEntity looks like:
@NodeEntity
public class Vertex {
private String name;
@GraphId
private Long id;
@Relationship(type = "PAIRS_WITH", direction = "UNDIRECTED")
public Set<Vertex> teammates;
public Vertex() { }
// getters, setters, equals, toString
}
The repository:
@Repository
public interface VertexRepository extends GraphRepository<Vertex> {
Vertex findByName(String name);
List<Vertex> findByTeammatesName(String name);
}
The service:
@Service
public class VertexServiceImpl implements VertexService {
@Autowired
private VertexRepository vertexRepository;
@Override
@Transactional
public Vertex create(Vertex vertex) {
return vertexRepository.save(vertex);
}
@Override
@Transactional
public Iterable<Vertex> findAll() {
return vertexRepository.findAll();
}
//....
}
Then I have a controller with two simple methods to save a vertex and then query the database.
@RestController
@RequestMapping("/api/")
public class GraphController {
@Autowired
VertexService vertexService;
@RequestMapping(value = "addvertex", method = RequestMethod.GET)
public void add() {
Vertex v = new Vertex();
v.setId(1l);
v.setName("name");
Vertex v2 = new Vertex();
v2.setId(2l);
v.worksWith(v2);
vertexService.create(v);
}
@RequestMapping(value = "all", method = RequestMethod.GET)
public Iterable<Vertex> getAll() {
return vertexService.findAll();
}
}
When I save the vertex to the db there is no error. When I call /all the db is empty. I checked messages.log and there is no exception...last lines being:
2016-03-26 14:25:15.716+0000 INFO [o.n.k.i.DiagnosticsManager] Interface Microsoft Wi-Fi Direct Virtual Adapter-WFP 802.3 MAC Layer LightWeight Filter-0000:
2016-03-26 14:25:15.716+0000 INFO [o.n.k.i.DiagnosticsManager] --- INITIALIZED diagnostics END ---
2016-03-26 14:25:15.747+0000 INFO [o.n.k.i.DiagnosticsManager] --- STOPPING diagnostics START ---
2016-03-26 14:25:15.747+0000 INFO [o.n.k.i.DiagnosticsManager] --- STOPPING diagnostics END ---
2016-03-26 14:25:15.747+0000 INFO [o.n.k.i.f.GraphDatabaseFacade] Shutdown started
Any help is fully appreciated!