I have a problem with sending a search request. i am using the criteria/criterion interfaces and restrictions.
Hibernate version:3
Name and version of the database you are using:Oracle9
i have to classes Image and Keyword, an Image has many Keywords, every Keyword has one Image:
Code:
@Entity
@Table(name = "IMAGES")
public class Image{
private Set<Keyword> keywords;
private String name;
public String getName() {
return name;
}
@OneToMany
public Set<Keyword> getKeywords() {
return keywords;
}
public void setKeywords(Set<Keyword> keywords) {
this.keywords = keywords;
}
public void setName(String name) {
this.name = name;
}
Code:
@Entity
@Table(name="KEYWORDS")
public class Keyword{
private String keywordname;
public String getKeywordname() {
return keywordname;
}
public void setKeywordname(String keyword) {
this.keywordname = keyword;
}
}
I want a searchcriterion for example find all images with name = xyz and which contains keywords with name =abc
the seperate search would be easy:
Code:
List a = handler.getSession().createCriteria(Image.class)
.createCriteria("keywords")
.add(Restrictions.like("keywordname", "abc", MatchMode.ANYWHERE)).list() ;
and
Code:
List b = handler.getSession().createCriteria.add(Restrictions.like("name","xyz",MatchMode.ANYWHERE)).list() ;
but how can i combine them? restrictions.and needs two Criterions but the first one gives me a criteria
mfg
adonay[/code]