0
GraphRepository 파생 된 파인더 방법에 문제가 있습니다.Neo4j GraphRepository 파생 검색 방법
짧은 버전 :
User foundUser1 = userRepository.findByEmail("[email protected]");
User foundUser2 = userRepository.findByPropertyValue("id", 1);
작품,하지만 :
User foundUser3 = userRepository.findById(1);
긴 버전 :
시험의 context.xml
,691 363,210<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
}
}
THIR findUser3이 null이므로 d assert가 실패합니다. findByPropertyValue("id" ..)
으로 찾을 수있는 동안 이것이 왜 일어나는지 이해할 수 없습니다. id이 키워드 일종인가 궁금합니다.
<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>
파생 된 파인더가 findByPropertyValue를 장면 뒤에서 사용한다고 추측했으나 외관상으로는 분명하지 않습니다. 감사합니다 – SelimOber
아니 그들은 사이퍼 쿼리를 생성, findByPropertyValue는 단순한 인덱스 조회, 파인더 파인더/훨씬 더 복잡 할 수 있습니다 –
SNAPSHOT은 SDN 2.1.RC4에있을 것입니다 –