I have a class declared as
@Entity
@Table(name = "word", schema = "public")
public class Word implements java.io.Serializable {
...
private ContentLanguage contentLanguage;
...
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "content_language_id", nullable = false)
public ContentLanguageT getContentLanguage() {
return this.contentLanguage;
}
public void setContentLanguage(ContentLanguage contentLanguage) {
this.contentLanguage = contentLanguage;
}
...
ContentLanguage is declared as
@Entity
@Table(name = "content_language", schema = "public")
public class ContentLanguage implements java.io.Serializable {
private int id;
private String value;
....
My action needs to query for all Words who’s ContentLanguage field has an id = 1
I thought I might be able to create a criteria against ContentLanguage class and then add this to a Criteria against the Word table but obviously this is not the way to do it.
Any ideas as I don’t want to have to go and start using SQL or HQL for what is a relatively simple task?
public String execute()
{
//DetachedCriteria criteria1 = DetachedCriteria.forClass(ContentLanguageT.class);
//criteria1.add(Restrictions.eq("id",1));
DetachedCriteria criteria = DetachedCriteria.forClass(WordT.class);
//criteria.add( criteria1 );
criteria.add(Restrictions.eq("contentLanguageT", Integer.valueOf( contentLangID )));
allWords = wordDao.findByCriteria( criteria, 0, 50);
return SUCCESS;
}
Word.contentLanguageis of typeContentLanguage. SO you can’t compare it with an integer. You may only compare it with a ContentLanguage. So, either you door you do
I really prefer HQL for such simple static queries. Isn’t the following much more readable and intuitive?