最近我一直在玩 Spring Data for Neo4j ( version 2.1.0.BUILD-SNAPSHOT
),我遇到了一个与它的 GraphRepository 接口相关的问题。
您可以编写一个方法,使用方法名称中包含的属性搜索 T 类的节点,如下所示:
public interface UserRepository extends GraphRepository<User> {
public User findByUsername(String username);
public User findById(Long id);
}
我的用户类:
@NodeEntity
public class User {
@GraphId
Long id;
@Indexed
private String username;
private String password;
...
}
还有我的applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package="package.for.services" />
<neo4j:repositories base-package="package.for.repositories" />
<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown" scope="singleton">
<constructor-arg value="/path/to/neo4j.db" />
<constructor-arg>
<map>
<entry key="allow_store_upgrade" value="true" />
</map>
</constructor-arg>
</bean>
</beans>
我的问题是该findById(Long id)
方法确实返回具有该特定 id 的节点,但findByUsername(String username)
确实返回null
而不是具有该特定用户名的节点。
任何帮助将不胜感激。