我需要一個HQL查詢,但我只是沒有得到它。HQL查詢選擇與NOT IN
SELECT * FROM Poll WHERE pid NOT IN (
SELECT pid FROM votes WHERE uid = 'theuserid')
我想Poll's的所有目錄回其中的uid 不表選票存在。
而且樂於助人是HQL查詢其中的UID 表票存在,但我想這是非常相似;-)
這些都是2類:
public class Poll {
private int pid;
private String name;
private String description;
private Date deadline;
private Set<Team> teams = new HashSet<Team>(0);
//some getter & setter
}
public class Vote {
private int vid;
private String uid;
private int pid;
private int tid;
private int votes;
//some getter & setter
}
燦smbdy請幫助我。我想這是一個與WHERE的連接,而不是像,但我只是沒有得到它。
謝謝!
這是者均基於Hibernate映射:
<hibernate-mapping>
<class name="package.model.Poll" table="poll">
<id name="pid" column="pid" >
<generator class="increment"/>
</id>
<property name="name" column="name" />
<property name="description" column="description" />
<property name="deadline" type="timestamp" column="deadline" />
<set name="teams" table="pollchoice"
inverse="false" lazy="false" fetch="select" cascade="all" >
<key>
<column name="pid" not-null="true" />
</key>
<many-to-many entity-name="knt.exceedvote.model.Team">
<column name="tid" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="package.model.Vote" table="votes">
<id name="vid" column="vid" >
<generator class="increment"/>
</id>
<property name="pid" column="pid" />
<property name="uid" column="uid" />
<property name="tid" column="tid" />
<property name="votes" column="votes" />
</class>
</hibernate-mapping>
你寫的查詢應該已經工作了。如果它不現在顯示什麼 – polin
你可以試試這個嗎? 'SELECT * FROM poll p LEFT JOIN票v對p.pid = v.pid' 'WHERE v.uid <>'theuserid'' – bonCodigo
@polin u是正確的,只需要在hql中修改;)這個工作原理: SELECT p FROM Poll p WHERE p.pid NOT IN(SELECT v.pid FROM Vote v WHERE v.uid ='123') – user1671980