Hi,
When loading an Entity with a @ManyToOne association in a neo4j datastore it seems the "one"-side of the relationship can't be reached using the property getter if the Entity is loaded with JP-QL or Cypher. But when loading with with EntityManager.find() it works. From the "many"-side both approaches work.
I've added a test case to hibernate-demos to illustrate. Have a look at AssociationTest.java, you can find it here :
https://github.com/shorke/hibernate-demos/tree/master/hibernate-ogm/nosql-with-hibernate-ogm-101/hibernate-ogm-demo-nosql-with-hibernate-ogm-101-part-1
This fails on assertThat(loadedHike.getOrganizer()).isNotNull();
Code:
@Test
public void loadHikeUsingPropertyJPQL() {
EntityManager entityManager = entityManagerFactory
.createEntityManager();
// load it back
entityManager.getTransaction().begin();
Hike loadedHike = entityManager
.createQuery("SELECT H From Hike H WHERE id = :id", Hike.class)
.setParameter("id", cornwall.getId()).getSingleResult();
assertThat(loadedHike).isNotNull();
assertThat(loadedHike.getOrganizer()).isNotNull();
assertThat(loadedHike.getOrganizer().getFirstName()).isEqualTo("Bob");
entityManager.getTransaction().commit();
}
While this works
Code:
@Test
public void loadHikeUsingId() {
EntityManager entityManager = entityManagerFactory
.createEntityManager();
// load it back
entityManager.getTransaction().begin();
Hike loadedHike = entityManager.find(Hike.class, cornwall.getId());
assertThat(loadedHike).isNotNull();
assertThat(loadedHike.getOrganizer()).isNotNull();
assertThat(loadedHike.getOrganizer().getFirstName()).isEqualTo("Bob");
entityManager.getTransaction().commit();
}
Thanks,
Staffan