0
我試圖用SDN(spring-data-neo4j 4.1.2.RELEASE)更新Neo4J社區版本3.0.3中的Person實體。我在更新實體時看到了一種行爲。使用SDN更新Neo4J實體的屬性
- 我創建了名爲「person」的'Person'實體並在數據庫(第8行)中保存了相同的 。
- 已更改已保存實體的屬性(fullName),但 未更新數據庫中的第10行。
- 從數據庫中檢索同一個人,但是通過將findBy方法引入另一個名爲「person2」行(12)的變量中。
- 變量「person」(第10行)中所做的更改丟失。
現在人和人2變量 都具有相同的屬性值。
1.Person person = new Person(); 2. person.setUuid(UUID.randomUUID().toString()); 3. person.setFullName("P1"); 4. person.setEmail("[email protected]"); 5. person.setUsername("[email protected]"); 6. person.setPhone("123456789"); 7. person.setDob(new Date()); 8. personService.create(person); 9. System.out.println(person); //Person{id=27, username='[email protected]', fullName='P1', email='[email protected]'} 10. person.setFullName("P2"); 11. System.out.println(person); //Person{id=27, username='[email protected]', fullName='P2', email='[email protected]'} 12.Person person2 = personService.findByEmail("[email protected]"); 13. System.out.println(person2); //Person{id=27, username='[email protected]', fullName='P1', email='[email protected]'} 14. System.out.println(person); //Person{id=27, username='[email protected]', fullName='P1', email='[email protected]'}
這是Neo4j的SDN的默認行爲?
下面給出的聚甲醛項目,以及用於Neo4j的配置作爲註釋
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<!-- <version>4.1.2.RELEASE</version> -->
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>2.0.4</version>
</dependency>
public class MyNeo4jConfiguration extends Neo4jConfiguration {
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config
.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
.setCredentials("neo4j", "admin")
.setURI("http://localhost:7474");
return config;
}
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "au.threeevolutions.bezzur.domain" );
}
}
我正在使用spring-data-neo4j 4.1.2.RELEASE。那麼我需要改用neo4j-ogm嗎?如果我正在切換,會在代碼中發生很多變化嗎?它是一個基於彈簧啓動的項目。我只在春天的數據上工作到日期(你可能已經注意到我以前的帖子) – Soumya
沒有必要下降到Neo4j OGM。只需在您的POM這種依賴關係: org.neo4j 的Neo4j-OGM核心 2.0.4 的,一個是司機看到http://neo4j.com/docs/ogm-manual/current /#_ dependencies_for_the_neo4j_ogm –
Luanne
我做了相應的更改。問題本身提供了修改。現在變量「person」和「person2」的「fullName」屬性的值都是「P2」。看起來,如果從數據庫中提取相同的節點,則這些節點中的本地更改會反映在提取的節點中。例如,我將變量「person1」的fullName的值更改爲「P2」。現在,當我使用findByEmail方法將變量「person2」中的同一個人的細節提取出來時,這個變量的fullName也是「P2」而不是「P1」,儘管我沒有堅持person1 – Soumya