0

I am running neo4j-community-2.2.5 locally on my macbook. I am trying to connect to the code using the neo4j-ogm version : 1.1.2

Here is the session factory:

public class Neo4jSessionFactory {

    private final static SessionFactory sessionFactory = new SessionFactory("com.readypulse.rpinfluencernetwork.ogm.model");
    private static Neo4jSessionFactory factory = new Neo4jSessionFactory();

    public static Neo4jSessionFactory getInstance() {
        return factory;
    }

    private Neo4jSessionFactory() {
    }

    public Session getNeo4jSession() {
        return sessionFactory.openSession("http://localhost:7474", "neo4j",  "mypassword");
    }
}

I have a entity class :

@NodeEntity(label="Hashtag")
public class Hashtag extends Entity {

    @Property(name = "name")
    String name;
...

Service :

public interface HashtagService extends Service<Hashtag>{

}

Generic Service:

public abstract class GenericService<T> implements Service<T> {

    private static final int DEPTH_LIST = 0;
    private static final int DEPTH_ENTITY = 1;
    private Session session = Neo4jSessionFactory.getInstance().getNeo4jSession();

    public Iterable<T> findAll() {
        return session.loadAll(getEntityType(), DEPTH_LIST);
    }

    public T find(Long id) {
        return session.load(getEntityType(), id, DEPTH_ENTITY);
    }

    public void delete(Long id) {
        session.delete(session.load(getEntityType(), id));
    }

    public void createOrUpdate(T entity) {
        session.save(entity, DEPTH_ENTITY);
    }

    public abstract Class<T> getEntityType();
}

Calling code :

public static void main(String args[]) {
    Hashtag hashtag = new Hashtag("fun");
    HashtagService service = new HashtagServiceImpl();

    service.createOrUpdate(hashtag);
}

I am running the code on eclipse as simple java process, and not on any Application server.

Here is the full log with trace:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/lazywiz/.m2/repository/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/lazywiz/.m2/repository/org/slf4j/slf4j-jdk14/1.5.11/slf4j-jdk14-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/lazywiz/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
15/10/09 14:55:16 INFO info.ClassFileProcessor: Starting Post-processing phase
15/10/09 14:55:16 INFO info.ClassFileProcessor: Building annotation class map
15/10/09 14:55:16 INFO info.ClassFileProcessor: Building interface class map for 9 classes
15/10/09 14:55:16 INFO info.ClassFileProcessor: Registering default type converters...
15/10/09 14:55:16 INFO info.ClassFileProcessor: Post-processing complete
15/10/09 14:55:16 INFO info.ClassFileProcessor: 9 classes loaded in 16 milliseconds
15/10/09 14:55:17 WARN request.DefaultRequest: Caught response exception: No Host
Exception in thread "main" org.neo4j.ogm.session.result.ResultProcessingException: Failed to execute request: {"statements":[{"statement":"CREATE (_0:`Hashtag`{_0_props}) RETURN id(_0) AS _0","parameters":{"_0_props":{"name":"varun"}},"resultDataContents":["row"],"includeStats":false}]}
    at org.neo4j.ogm.session.request.DefaultRequest.execute(DefaultRequest.java:105)
    at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRequestHandler.java:99)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:68)
    at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:391)
    at com.readypulse.rpinfluencernetwork.ogm.service.GenericService.createOrUpdate(GenericService.java:26)
    at com.readypulse.rpinfluencernetwork.GraphManager.main(GraphManager.java:16)
Caused by: org.apache.http.client.HttpResponseException: No Host
    at org.neo4j.ogm.session.request.DefaultRequest.execute(DefaultRequest.java:86)
    ... 5 more

Can someone please suggest where I am going wrong. Prior to this I was having a totally different code base where I was using

graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath); and 

But later I realized that this is not the right way when I want to connect to the neo4j server running in prod environment. I want to start the server and hence connect is via java and Ruby client concurrently.

Thanks!

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
lazywiz
  • 1,091
  • 2
  • 13
  • 26
  • You've probably already checked but are you sure that your neo4j server is accessible? curl to http://localhost:7474/db/data/ ? – Luanne Oct 11 '15 at 16:48
  • Yeh it is accessible. I added aa JDBC connector and it works, but I still want to get the OGM working, but no luck so far. – lazywiz Oct 12 '15 at 17:26
  • Please set org.neo4j.ogm log level to debug and check the URL is POSTs to – Luanne Oct 12 '15 at 17:28
  • I checked that already by step debug, its pointing to correct url. – lazywiz Oct 12 '15 at 23:27

1 Answers1

0

Some points :

a) You can not use neo4j as password, this is the default password when you install a new database, but the password need to be changed at first start.

For changing the password :

  1. Open the Neo4j browser and the first prompt will ask you to change the password

  2. Or issue a curl request for changing the password :

    curl -H "Content-Type: application/json"\
    -H "Authorization: Basic echo -n 'neo4j:neo4j' | base64"\
    -X POST -d '{"password":"yourNewPassword"}'\
    -I http://localhost:7474/user/neo4j/password

b) If you're not using SDN4, In the sessionFactoryyou need to pass the user and password as arguments to the openSession method:

Session session = sessionFactory.openSession("http://localhost:7474", username, password);

Docs :

Neo4j Authentication: http://neo4j.com/docs/stable/rest-api-security.html#rest-api-user-status-on-first-access

Neo4j OGM Session Authentication : http://neo4j.com/docs/ogm/java/stable/#reference_programming-model_session

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
  • Thanks Christophe for the comments. I did update the password before, was just pasting a fake one in stackoverflow. For the openSession() I tried using password and username, still no luck. – lazywiz Oct 09 '15 at 22:47