Neo4j GraphRepository derived finder methods

老子叫甜甜 提交于 2019-12-12 05:13:11

问题


I have a problem with derived finder methods of GraphRepository.

Short version:

User foundUser1 = userRepository.findByEmail("test@gmail.com");
User foundUser2 = userRepository.findByPropertyValue("id", 1);

works, but not:

User foundUser3 = userRepository.findById(1);

Long version:

test-context.xml

<context:annotation-config/>    
<neo4j:config storeDirectory="data/graph.db" />
<neo4j:repositories base-package="com.blbl.repository"/>
<tx:annotation-driven mode="proxy"/>

UserGraphRepository.java:

public interface UserGraphRepository extends GraphRepository<User> {
    public User findById(int id);
    public User findByEmail(String email);    
}

User.java:

@NodeEntity
public class User {
    @GraphId private Long nodeId;
    @Indexed(unique = true) private int id;
    @Indexed private String email;

    public User(int id) {
        this.id = id;
    }
    // getter & setters
}

Test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/test-context.xml"})
@Transactional
public class UserServiceTest {

    @Autowired
    private UserGraphRepository userRepository;

    @Autowired
    private Neo4jTemplate template;


    @BeforeTransaction
    @Rollback(value = false)
    public void cleanDb() {
        Neo4jHelper.cleanDb(template);
    }

    @Test
    public void testSaveUser() {
        User user = userRepository.save(new User(1));
        user.setEmail("test@gmail.com");
        userRepository.save(user);

        User foundUser1 = userRepository.findByEmail("test@gmail.com");
        User foundUser2 = userRepository.findByPropertyValue("id", 1);
        User foundUser3 = userRepository.findById(1);
        assertThat(foundUser1, is(notNullValue())); // SUCCESS
        assertThat(foundUser2, is(notNullValue())); // SUCCESS
        assertThat(foundUser3, is(notNullValue())); // FAILS
    }
}

third assert fails since foundUser3 is null. I don't understand why this is happening while it can find with findByPropertyValue("id" ..). I wonder if id is some sort of keyword? (Note that my @GraphId is called nodeId)

PS:

<neo4j-version>1.8.M07</neo4j-version>
<org.springframework.version>3.1.2.RELEASE</org.springframework.version>
<org.springframework-data-neo4j.version>2.1.0.RC3</org.springframework-data-neo4j.version>

回答1:


This is probably an issue with special indexing of numeric fields. I raised an issue here: https://jira.springsource.org/browse/DATAGRAPH-294



来源:https://stackoverflow.com/questions/12334708/neo4j-graphrepository-derived-finder-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!