我当前的配置
class Neo4jSessionFactory (implicit inj: Injector) extends Injectable {
val neo4jHost = inject [String] (identified by "neo4j.server.host")
val neo4jPort = inject [Integer] (identified by "neo4j.server.port")
val neo4jDb = inject [String] (identified by "neo4j.server.db")
val neo4jUser = inject [String] (identified by "neo4j.server.user")
val neo4jPass = inject [String] (identified by "neo4j.server.pass")
def neo4jServer() : Neo4jServer = {
return new RemoteServer("http://localhost:7474", "neo4j", "neo4j");
}
def getNeo4jConfiguration : Configuration = {
var config = new Configuration
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
.setURI("http://neo4j:neo4j@localhost:7474")
return config
}
def getNeo4jSessionFactory: SessionFactory = {
System.setProperty("username", "neo4j")
System.setProperty("password", "neo4j")
var config = getNeo4jConfiguration
return new SessionFactory(getNeo4jConfiguration,"domain")
}
def getNeo4jTemplate : Neo4jOperations = {
return new Neo4jTemplate(getNeo4jSession)
}
def getNeo4jSession : Session = {
return getNeo4jSessionFactory.openSession
}
和我的Controller类
class Application (implicit inj : Injector) extends Controller with Injectable {
val neo4jService = inject[Neo4jSessionFactory]
val session = neo4jService.getNeo4jTemplate
def insertStudentNeo4j(name: String, age: Int) = Action { implicit request =>
val test = new domain.Student
test.name=Option(name).getOrElse("default").toString
test.age=Option(age).getOrElse(0).toInt
session.save(test)
// var jason = MyJsonUtil.convertStudentToJsonOrig(test)
Ok(Json.obj("Name:" -> name))
}
当我尝试将对象保存到neo4j时,它返回NullPointerException
并尝试println(session)
和println(test)
它们都不为空,我仍然想知道原因是什么?
这是我的学生班
@NodeEntity
class Student extends Entity {
var name: String = _
var age: Int = _
var txt: String = _
def this(name: String, age: Int, txt: String) = {
this()
this.name=name
this.age=age
this.txt=txt
}
}
和我的实体类,其中包含一个不分配值的graphId。
abstract class Entity {
@GraphId
@BeanProperty
var graph_id: java.lang.Long = _
override def equals(o: Any): Boolean = o match {
case other: Entity => other.graph_id.equals(this.graph_id)
case _ => false
}
}