2012-10-19 32 views
1

最近我一直在使用Spring Data for Neo4j(version 2.1.0.BUILD-SNAPSHOT),我遇到了與它的GraphRepository接口有關的問題。Null返回使用Spring Data的GraphRepository for Neo4j

你可以寫,將使用包含在方法的名稱屬性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)方法不retur n具有該特定ID的節點,但findByUsername(String username)確實會返回null,而不是具有該特定用戶名的節點。

任何幫助將不勝感激。

回答

0

通過重新創建數據庫來解決。刪除其目錄並再次啓動應用程序。

我猜索引自開始以來還沒有被正確創建,並且Spring數據一旦創建就無法更改它們。

謝謝。

相關問題