Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: @ManyToOne association not correctly loaded with neo4j
PostPosted: Tue Jun 16, 2015 11:55 am 
Newbie

Joined: Tue Jun 16, 2015 11:25 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: @ManyToOne association not correctly loaded with neo4j
PostPosted: Wed Jun 17, 2015 4:53 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

This seems to be a bug. I've filed https://hibernate.atlassian.net/browse/OGM-854 for it. Thanks for providing the test, very helpful for reproducing it.

Cheers,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: @ManyToOne association not correctly loaded with neo4j
PostPosted: Wed Jun 17, 2015 7:41 am 
Newbie

Joined: Tue Jun 16, 2015 11:25 am
Posts: 2
Thanks! I'll follow it from there.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.