Search code examples
javadatabasejpanamed-query

Java EE named query join


I have two entities

   @Entity    
    public class Tabulka{

@OneToMany(mappedBy = "tabulka")
    private List<VysledkyHraca> vysledkyHraca;
.
.
.

}

and

    @Entity
    public class VysledkyHraca{

    @ManyToOne
        private Tabulka tabulka;
.
.
.

    }

this created to tables: tabulka with with id and ... and VysledkyHraca with id .. and id_tabulka

If I want to retrive all tabulka... well, it's pretty Easy:

@NamedQuery(name = Tabulka.Q_GET_ALL_TABULKY, query = "SELECT t FROM Tabulka t ")

but now I want to retrive all tabulka and then list of VysledkyHraca

I try this @NamedQuery(name = Tabulka.Q_GET_ALL_JOINTABULKY, query = "SELECT t FROM Tabulka t join t.vysledkyHraca") but it doesnt work. thx for help


Solution

  • join requires an alias

    If you just want it fetched, use "join fetch" (with no alias)