2012-11-02 79 views
1

我有以下HQL語句:HQL和繼承

Query q = session.createQuery(
     "SELECT ze " + 
     "FROM NormaleZone zo " + 
     "LEFT JOIN zo.zaal za " + 
     "LEFT JOIN za.vertoningen v " + 
     "LEFT JOIN zo.normaleZetels ze " + 
     "WHERE v = :vertoning " + 
     " AND zo = :zone " + 
     " AND ze NOT IN (SELECT t.zetel FROM Ticket t WHERE t.vertoning = :vertoning)" 
    ); 

我的問題是,從ZoneNormaleZone繼承,因爲這樣做HandicapZoneLoveZone

我想這樣做的是以下幾點:

Query q = session.createQuery(
     "SELECT ze " + 
     "FROM Zone zo " + 
     "LEFT JOIN zo.zaal za " + 
     "LEFT JOIN za.vertoningen v " + 
     "LEFT JOIN zo.??? ze " + 
     "WHERE v = :vertoning " + 
     " AND zo = :zone " + 
     " AND ze NOT IN (SELECT t.zetel FROM Ticket t WHERE t.vertoning = :vertoning)" 
    ); 

你可以看到我把zo.???在那裏。這個HQL的目標是找出哪些座位尚未在電影院拍攝。問題在於抽象類Zone沒有座位(ze將成爲座位的別名)。

我不明白我怎麼能解決這個問題,除了看着那個方法傳入Zone對象,然後做兩個字符串,一個區域,一個用於席位,然後在HQL字符串拼接它們。

回答

4

有一個隱藏的屬性,它表示一個對象的類。使用ze.class = :seatclass和(「seatclass」,Seat.class)