ドキュメントエンティティにOneToMany関係が設定されているブックエンティティがあります。言い換えれば、Hibernateでは、私のブックエンティティは、ドキュメントのリストをプロパティドキュメントとして返します。問合せで比較するコレクションのノードを解決するJPQLの問題
まだ書籍に割り当てられていないユーザーのドキュメントリストを返信したいと思います。ここに私のJPQLクエリがある、と私はそれを私ができるあらゆる方法をfinagledてきた、と私はそれが仕事を得ることはできません。
ブックは、ユーザーが、b.docsに渡されたエンティティのエンティティですselect d from Document d WHERE d.user = :user
AND NOT EXISTS(SELECT b.docs from Book b WHERE b.docs = d)
文書のリストであり、文書(d)はエンティティである。
私は間違っていますか?
org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Collection(com.fallenjusticestudios.bardwalk.model.Book.docs) : com.fallenjusticestudios.bardwalk.model.Document]
帳:
@Entity
@Table(name="book")
public class Book {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Column
@NotEmpty
@NotNull
private String title;
@Column
@NotEmpty
@NotNull
private String description;
@ManyToOne(cascade=CascadeType.MERGE, targetEntity=User.class)
@JoinColumn(name="user")
private User user;
@OneToMany(cascade=CascadeType.MERGE, fetch=FetchType.LAZY, targetEntity=Document.class)
@JoinColumn(name="document_id",referencedColumnName="id")
private List<Document> docs;
// Will need to add Contest to the fields later on.
//
//
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public User getUser() {
return user;
}
public List<Document> getDocs() {
return docs;
}
public void setId(Long id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setUser(User user) {
this.user = user;
}
public void setDocs(List<Document> docs) {
this.docs = docs;
}
}
UPDATE:
もう一つの試み:
問合せ:
select d from Document d WHERE d.user = :user
AND NOT EXISTS(SELECT Document from Book.docs b WHERE b.id = dn.id)
クエリのこの特定のバージョンでは、私はエラーを受信しています
org.hibernate.hql.ast.QuerySyntaxException: Book.docs is not mapped [select d from com.fallenjusticestudios.bardwalk.model.Document d WHERE d.user = :user AND NOT EXISTS(SELECT Document from Book.docs b WHERE b.id = dn.id)]
更新日2:
私はこれを理解しました。私は質問をすべて間違っていた。ソリューションクエリ:
select d from Document d WHERE d.user = :user
AND NOT d IN(SELECT d from Book b, IN(b.docs) bd WHERE bd.id = d.id)