getHibernateTemplate().find("select s.* from Catalog c,Subcatalog s where c.catalogid=s.catalogid order by c.catalogid");
会出现ERROR: org.hibernate.hql.PARSER#reportError : line 1:19: expecting IDENT, found '*' 怎么解决?还有一个小问题,关于泛型的警告可以忽略吗?
// 执行HQL查询,返回查询的结果
public List<? extends Object> find(String where) {
return getHibernateTemplate().find(where);
}
如果List后不加<? extends Object>,就出现警告,如果加了,调用的时候转换List又出现警告了
会出现ERROR: org.hibernate.hql.PARSER#reportError : line 1:19: expecting IDENT, found '*' 怎么解决?还有一个小问题,关于泛型的警告可以忽略吗?
// 执行HQL查询,返回查询的结果
public List<? extends Object> find(String where) {
return getHibernateTemplate().find(where);
}
如果List后不加<? extends Object>,就出现警告,如果加了,调用的时候转换List又出现警告了
这样是可以的,呵呵!
将你的Subcatalog s 中的所有字段都列出来就可以了,不要用*号
2,List<? extends Object>泛型,加上的话,应该要具体制定类型。调用也需要制定的。(一般有些警告可以忽略)
subcatlist = (ArrayList<Subcatalog>) subcatalogService
.find("s.* from Catalog c,Subcatalog s where c.catalogid=s.catalogid order by c.catalogid");
request.setAttribute("subcatlist", subcatlist);
哪有这样的写法的啊~~~
你把Subcatalog中的字段都列出来不就可以了么??
或者你select new Subcatalog() from Catalog c,Subcatalog s where c.catalogid=s.catalogid order by c.catalogid
前提Subcatalog类中必须有构造方法,
subcatlist = (ArrayList<Subcatalog>) subcatalogService
.find("select new Subcatalog() from Catalog c,Subcatalog s where c.catalogid=s.catalogid order by c.catalogid");
request.setAttribute("subcatlist", subcatlist);出现错误org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: ) near line 1, column 23 [select new Subcatalog() from com.gcl.model.Catalog c,com.gcl.model.Subcatalog s where c.catalogid=s.catalogid order by c.catalogid]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ) near line 1, column 23 [select new Subcatalog() from com.gcl.model.Catalog c,com.gcl.model.Subcatalog s where c.catalogid=s.catalogid order by c.catalogid]
没写全面,不好意思select new Subcatalog(这里面要放你的Subcatalog中的字段啊) from Catalog c,Subcatalog s where c.catalogid=s.catalogid order by c.catalogid
import java.util.HashSet;
import java.util.Set;/**
* Subcatalog entity. @author MyEclipse Persistence Tools
*/public class Subcatalog implements java.io.Serializable { // Fields private Integer subcatalogid;
private Catalog catalog;
private String subcatalogname;
private String subcatalogurl;
private Set rssurlses = new HashSet(0);
private Set newses = new HashSet(0); // Constructors /** default constructor */
public Subcatalog() {
} /** full constructor */
public Subcatalog(Catalog catalog, String subcatalogname,
String subcatalogurl, Set rssurlses, Set newses) {
this.catalog = catalog;
this.subcatalogname = subcatalogname;
this.subcatalogurl = subcatalogurl;
this.rssurlses = rssurlses;
this.newses = newses;
} // Property accessors public Integer getSubcatalogid() {
return this.subcatalogid;
} public void setSubcatalogid(Integer subcatalogid) {
this.subcatalogid = subcatalogid;
} public Catalog getCatalog() {
return this.catalog;
} public void setCatalog(Catalog catalog) {
this.catalog = catalog;
} public String getSubcatalogname() {
return this.subcatalogname;
} public void setSubcatalogname(String subcatalogname) {
this.subcatalogname = subcatalogname;
} public String getSubcatalogurl() {
return this.subcatalogurl;
} public void setSubcatalogurl(String subcatalogurl) {
this.subcatalogurl = subcatalogurl;
} public Set getRssurlses() {
return this.rssurlses;
} public void setRssurlses(Set rssurlses) {
this.rssurlses = rssurlses;
} public Set getNewses() {
return this.newses;
} public void setNewses(Set newses) {
this.newses = newses;
}}
.createSQLQuery(
"select {s.*} from Catalog c,Subcatalog {s} where c.catalogid=s.catalogid order by c.catalogid",
"s", Subcatalog.class);
return list; public List createSQLQuery(String hsql,String name,Class obj) {
Session session = this.openSession();
Query query = session.createSQLQuery(hsql).addEntity(name,obj);
return query.list();
}
我是这么解决的