hibernate query返回的list 里面的对象都是Object 无法转换成我要的类型
这是hibernate输出的sql语句selectservice0_.idasid10_0_,s_category1_.idasid9_1_,service0_.name...
这是hibernate输出的sql语句
select
service0_.id as id10_0_,
s_category1_.id as id9_1_,
service0_.name as name10_0_,
service0_.base_price as base3_10_0_,
service0_.vip_price as vip4_10_0_,
service0_.profile as profile10_0_,
service0_.service_image as service6_10_0_,
service0_.cate_id as cate7_10_0_,
s_category1_.name as name9_1_,
s_category1_.description as descript3_9_1_
from
service service0_
inner join
s_category s_category1_
on service0_.cate_id=s_category1_.id limit ?
hibernate映射:
<class name="Service" table="service">
<id name="id" type="integer" column="id">
<generator class="native"></generator>
</id>
<property name="name" type="string" column="name"></property>
<property name="base_price" type="double" column="base_price"></property>
<property name="vip_price" type="double" column="vip_price"></property>
<property name="profile" type="string" column="profile"></property>
<property name="service_image" type="string" column="service_image"></property>
<set name="brands" table="brandservice" inverse="false" lazy="true">
<key column="service_id"></key>
<many-to-many class="Brand" column="brandid"></many-to-many>
</set>
<many-to-one name="cate" class="S_category" column="cate_id" fetch="join"></many-to-one>
</class>
service 类属性:属性都私有 get/set没错的
int id;private name;double base_price;
double vip_price ;String profile;String service_image;
S_category cate;Set<Brand> brands; 展开
select
service0_.id as id10_0_,
s_category1_.id as id9_1_,
service0_.name as name10_0_,
service0_.base_price as base3_10_0_,
service0_.vip_price as vip4_10_0_,
service0_.profile as profile10_0_,
service0_.service_image as service6_10_0_,
service0_.cate_id as cate7_10_0_,
s_category1_.name as name9_1_,
s_category1_.description as descript3_9_1_
from
service service0_
inner join
s_category s_category1_
on service0_.cate_id=s_category1_.id limit ?
hibernate映射:
<class name="Service" table="service">
<id name="id" type="integer" column="id">
<generator class="native"></generator>
</id>
<property name="name" type="string" column="name"></property>
<property name="base_price" type="double" column="base_price"></property>
<property name="vip_price" type="double" column="vip_price"></property>
<property name="profile" type="string" column="profile"></property>
<property name="service_image" type="string" column="service_image"></property>
<set name="brands" table="brandservice" inverse="false" lazy="true">
<key column="service_id"></key>
<many-to-many class="Brand" column="brandid"></many-to-many>
</set>
<many-to-one name="cate" class="S_category" column="cate_id" fetch="join"></many-to-one>
</class>
service 类属性:属性都私有 get/set没错的
int id;private name;double base_price;
double vip_price ;String profile;String service_image;
S_category cate;Set<Brand> brands; 展开
3个回答
展开全部
for循环
for (Iterator ite = list.iterator(); ite.hasNext();) {
Object[] obj = (Object[]) ite.next();
System.out.println(obj[1]);
System.out.println(obj[2]);
}
这样试试呢?
for (Iterator ite = list.iterator(); ite.hasNext();) {
Object[] obj = (Object[]) ite.next();
System.out.println(obj[1]);
System.out.println(obj[2]);
}
这样试试呢?
追问
from Service s join s.cate c
hql语句是这样写的
用这种循环的话 返回obj[0] 和obj[1]两个对象
但是我没查字段啊。。。 为什么会返回对象数组
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用迭代器就可了
Iterator it = al.Iterator();
it.get你要的类型就ok!!
Iterator it = al.Iterator();
it.get你要的类型就ok!!
追问
大哥 就是迭代的时候报错了啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
莫非你没写映射配置?
更多追问追答
追问
都写了的
追答
去掉fetch属性试试,我自己的工程加了以后也转不了了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询