hql和继承

时间:2012-11-02 12:00:22

标签: hibernate 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)"
    );

我遇到的问题是NormaleZone继承自ZoneHandicapZoneLoveZone也是如此。

我想做的是以下内容:

    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字符串中连接它们

1 个答案:

答案 0 :(得分:4)

有一个隐藏属性,表示对象的类。使用ze.class = :seatclass和(“seatclass”,Seat.class)