Search code examples
javamongodbhibernatehibernate-ogm

How to retrieve embedded objects using Hibernate OGM


I have two classes, where one is an entity and the other one is an @Embeddable object:

@Entity
public class A {
    @Id
    ...
    protected Integer id;
    @Embedded
    protected B b;
    protected String c;
}


@Embeddable
public class B {
    protected String d;
}

When i persist these in MongoDB, it works perfectly fine. But when I query a tuple of A, b is null.

This is how I tried querying:

A a = em.find(A.class, 1);
A a = (A) em.createQuery("SELECT a FROM A a").getSingleResult();
A a = (A) em.createNativeQuery(A.class, "{}").getSingleResult();

Can somebody tell me how to solve this problem?


Solution

  • This bug has been solved some time ago. This should work with the latest Hibernate OGM version