ssh [Ljava.lang.Object; cannot be cast to 的问题
List<Goods> list =getHibernateTemplate().find(
"select g.goodsid,g.goodsname,g.introduce,g.image,g.addr," +
"gt.typename,g.price,g.time " +
"from Goods g,Goodstype gt where g.goodstype = gt.goodstypeid and g.istop='1'");
System.out.println(list.get(0).getGoodsname());
错误信息
Struts has detected an unhandled exception:
Messages: [Ljava.lang.Object; cannot be cast to domain.Goods
File: dao/TopDAO.java
Line number: 18
--------------------------------------------
Stacktraces
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to domain.Goods
Goods类
public class Goods {
private String goodsid; //作为String是原作者设计不良?
private String goodsname;
private String introduce;
private String image;
private String addr;
private int goodstypeid;
private String typename;
private Goodstype goodstype;
private String istop;
private String isrecomm;
private Date time;//最新的更新时间
private String price;//最新的价格
//getter、setter略
}
hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 指定Hibernate映射文件的DTD信息 -->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="domain">
<class name="Goods" table="goods">
<!-- 读写缓存 -->
<cache usage="read-write"/>
<id name="goodsid" type="string"/>
<property name="goodsname" type="string" length="50"/>
<property name="introduce" type="string" length="50"/>
<property name="image" type="string" length="50"/>
<property name="addr" type="string" length="50"/>
<property name="istop" type="string" length="50"/>
<property name="isrecomm" type="string" length="50"/>
<property name="price" type="string" length="50"/>
<property name="time" type="date" length="50"/>
<!-- 映射和Goodstype的关联关系 -->
<many-to-one name="goodstype" column="goodstypeid"
class="Goodstype" not-null="true"/>
</class>
</hibernate-mapping>
困扰挺久了,求解答。
ssh
错误
------解决方案--------------------
该回复于2013-04-17 17:12:58被管理员删除