I have a Tag class like this:
public class Tag {
private Long id;
private String title;
private Set<Document> documents = new HashSet<Document>();
public Tag(){}
//getter and setter...
}
And a class Document clasified by some tags object
public class Document {
private Long id;
private String title;
private Int numberPages;
private Set<Tag> tags = new HashSet<Tag>();
public Document(){}
//getter and setter...
}
And now I would like get documents with a 10 pages maximun and they have tags “short” OR “essay”
I guess something like:
int nPages = 10;
Query query = session.createQuery("from Document where nPages <= :numberPages and (<<short>> OR <<essay>>);
query.setInteger("numberPages", nPages);
The list of tags could be variable. And I would like differentiate when have to be all tags (“AND” between tags) or with any tag is enough (“OR” between tags)
How can I build the sql statement?
I think your
HQLshould look like below: