나는 현재 neo4j 봄 데이터가 스프링 데이터 안녕하세요 - 세계 같은 cineast 프로젝트 및 기타 샘플을 감사 배울 수있는 몇 가지 테스트 샘플을 구현하고있어 ...Neo4j 노드 지속성 문제의 경우
는 불행하게도, 난 ' m 이제는 내 코드와 다른 샘플 코드에 대한 일식 디버거에서 보상을 시도하고 해결책을 찾기 위해 이미 시간을 보냈다하더라도 이해할 수없는 문제에 직면했다.
@NodeEntity
public class SimplePersonImpl {
@GraphId
private Long nodeId;
@Indexed
private String id = null;
@Indexed(indexType=IndexType.FULLTEXT, indexName = "LastName")
private String lastName = null;
@Indexed(indexType=IndexType.FULLTEXT, indexName = "FirstName")
private String firstName = null;
public SimplePersonImpl() {
}
public SimplePersonImpl(String firstName_, String lastName_) {
this.firstName=firstName_;
this.lastName=lastName_;
this.id=this.firstName+"."+this.lastName;
}
public String getID() {
return this.id;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public void setID(String id_) {
this.id=id_;
}
public void setFirstName(String firstName_) {
this.firstName=firstName_;
}
public void setLastName(String lastName_) {
this.lastName=lastName_;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimplePersonImpl person = (SimplePersonImpl) o;
if (nodeId == null) return super.equals(o);
return nodeId.equals(person.nodeId);
}
@Override
public int hashCode() {
return nodeId != null ? nodeId.hashCode() : super.hashCode();
}
@Override
public String toString() {
return String.format("Person{first name='%s', last name='%s'}", firstName, lastName);
}
}
I : 정말 사소한 사용 사례 있어야한다해도 나는 Neo4j의 지속성을 검증 할 수 없기 때문에이 문제는 특히 내가 테스트 해요 여기
클래스는 ... 나를 위해 차단 현재이 클래스를 테스트 중입니다. 다음과 같은 jUnit 테스트 케이스에 감사드립니다.@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/yes-test-context.xml"})
@Transactional
public class SimplePersonImplTest {
@Autowired Neo4jTemplate template;
@Rollback(false)
@BeforeTransaction
public void cleanUpGraph() {
Neo4jHelper.cleanDb(template);
}
@Test @Transactional
public void persistedPersonShouldBeRetrievableFromGraphDB() {
SimplePersonImpl qqun = template.save(new SimplePersonImpl());
SimplePersonImpl retrievedQqun = template.findOne(qqun.getNodeId(), SimplePersonImpl.class);
assertEquals("retrieved person matches persisted one", qqun, retrievedQqun);
}
@Test @Transactional
public void persistedPersonWithPropertiesShouldBeRetrievableFromGraphDB() {
SimplePersonImpl qqun = template.save(new SimplePersonImpl("testFN","testLN"));
SimplePersonImpl retrievedQqun = template.findOne(qqun.getNodeId(), SimplePersonImpl.class);
assertEquals("check memory first name matches persisted one", qqun.getFirstName(), retrievedQqun.getFirstName());
assertEquals("check memory last name matches persisted one", qqun.getLastName(), retrievedQqun.getLastName());
}
}
첫 번째 테스트는 성공적으로 실행되었지만 두 번째 테스트는 실패합니다. 이클립스 디버거로 확인할 때 다음과 같은 결과를 볼 수 있습니다 :
- 저장 방법 후에 올바른 firtName, lastName 및 id 값을 사용하여 SimplePersonImpl qqun을 반환하십시오. 하지만 nodeId는 null이며 왜 그 이유는 모르겠다. 그러나이 동작은 스프링 데이터 안녕 세상 샘플에서 동일하므로 내 문제가 거기에서 오지 않는다고 생각합니다. 노드 아이디 내 qqun 내가이 값을 오는 곳에서 이해하지 않는 qqun.getNodeId() 반환 1. 객체 만의는
- findOne 방법은 retrievedQqun를 돌려 계속하자에 null의 경우에도 findOne 방법에
- . 모든 retrievedQqun 속성은 null이며 firstName에 대한 첫 번째 assertEquals가 실패하는 이유 인 것 같습니다.
여기서 나는 내가 어디에서 잘못했는지 이해하지 못한다.하지만 나는 스프링 데이터 neo4j 지속성에 많은 것들이 있다는 것을 분명히 알지 못한다. 나는이 점들에 대한 해답을 얻게되어 기쁠 것이다. (save 호출 후 nodeId = null이 나타나는 이유는 무엇인가? 왜 모든 속성이 null이 아닌 null 객체를 검색 하는가? ...). 약간의 오차가있을 수
마지막 점은 내 테스트 환경 구성이지만 문제가 될 수있는 곳 내가 다시는 볼 수 없습니다 :
<?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:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="yes.ds.domain.neo4j"/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<!-- <neo4j:config storeDirectory="target/neo4j-db"/> -->
<neo4j:repositories base-package="yes.ds.repository.neo4j"/>
<tx:annotation-driven mode="proxy"/></beans>
당신에게
당신의 혼란은 aspectj가 가로 채기에서 오는 것이라고 생각합니다. 클래스 내에서 필드 액세스를 가로 채고 대신이 값에 대한 노드 속성을 살펴 봅니다. 클래스의 필드는 고려되지 않습니다. getter가 값을 반환하지 않습니까? 실험으로 : 생성자의 필드를 외부 또는 설정자로 직접 설정하는 대신 설정할 수 있습니까? –
save 호출 전에 setter를 사용하여 테스트를 마쳤습니다. 동일한 문제가 발생합니다 ... – echinopsii
문제점에 대한 해결책을 찾았습니다. 귀하의 문제와 직접 관련이 있는지 확신 할 수 없지만 ([At] RelatedToVia Relationships 용) 사용자 정의 관계 클래스를 작성한 경우 해당 클래스를 사용하여 작성된 관계에 자동으로 패키지 및 클래스 이름과 함께 __type__ 특성이 있습니다 클래스의. 관계를 작성하는 [at] Query가있는 경우 해당 조회는 __type__ 특성도 작성하지 않습니다. 이로 인해 관계가 나중에로드 될 때 문제가 발생하여 누락 된 __type__ 속성 문제가 발생합니다. 희망이 도움이됩니다! –