简体   繁体   中英

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

join requires an alias

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

You are still selecting Tabulkas in the second query. Try:

 SELECT vh FROM Tabulka t join t.vysledkyHraca vh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM