Search code examples
javahibernatecriteria

Hibernate criteria - one side mapped, criteria from other side


I have a question.

I have class A:

public class A {
    mapped id
    mapped name
}

and class B:

public class B {
    mapped @OneToMany List<A>
    mapped name
}

How can I create criteria, that is created on class "A", and get their associated class "B"?


Solution

  • For posterity:

    public class A {
        mapped id
        mapped name
        @ManyToOne B b;
    }
    
    public class B {
        mapped @OneToMany(mappedBy="b") List<A>
        mapped name
    }
    

    There is another solution with HQL, but i don't want to use it;