Методы поиска, производные от Neo4j GraphRepository

У меня проблема с производными методами поиска GraphRepository.

Краткая версия:

User foundUser1 = userRepository.findByEmail("[email protected]");
User foundUser2 = userRepository.findByPropertyValue("id", 1);

работает, но не:

User foundUser3 = userRepository.findById(1);

Длинная версия:

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
}

Тест:

@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("[email protected]");
        userRepository.save(user);

        User foundUser1 = userRepository.findByEmail("[email protected]");
        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
    }
}

третье утверждение терпит неудачу, так как foundUser3 имеет значение null. Я не понимаю, почему это происходит, когда он может найти с findByPropertyValue("id" ..). Интересно, является ли id каким-то ключевым словом? (Обратите внимание, что мой @GraphId называется 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>

person SelimOber    schedule 08.09.2012    source источник


Ответы (1)