0

GraphRepository の派生ファインダー メソッドに問題があります。

短縮版:

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

動作しますが、動作しません:

User foundUser3 = userRepository.findById(1);

長いバージョン:

テストコンテキスト.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);    
}

ユーザー.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("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
    }
}

foundUser3 が null であるため、3 番目のアサートは失敗します。で見つけることができるのに、なぜこれが起こっているのかわかりませんfindByPropertyValue("id" ..)idはある種のキーワードなのだろうか?@GraphId( myは と呼ばれることに注意してください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>
4

1 に答える 1

0

これはおそらく、数値フィールドの特別なインデックス付けの問題です。ここで問題を提起しました: https://jira.springsource.org/browse/DATAGRAPH-294

于 2012-09-09T23:24:52.710 に答える