テーブルから 1 列だけを返したい。これは私のDAOです:
@SuppressWarnings("unchecked")
public String getUri() {
return sessionFactory.getCurrentSession()
.createQuery("uri from Templates WHERE state=1").toString();
}
Uri は列です。ドメイン:
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
コンソールは次のように述べています。
Request processing failed; nested exception is java.lang.IllegalArgumentException: node to traverse cannot be null!
2 番目のバージョン:
@SuppressWarnings("unchecked")
public String getUri() {
return (String) sessionFactory.getCurrentSession()
.createQuery("select uri from TEMPLATES WHERE state=1")
.uniqueResult();
}
コンソール:
Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: TEMPLATES is not mapped [select uri from TEMPLATES WHERE state=1]