为了账号安全,请及时绑定邮箱和手机立即绑定

select字句问题

为什么我和老师一样使用了select字句我查询的时候还是查询了其他列的数据,而且是给select字句指定的列名查询了两遍。代码如下

private static void testquery4(Session session) {
    String hql = "select s.name,s,tel,s.address,s.star from SellerEntity s";
    Query query = session.createQuery(hql);
    List<Object[]> list = query.list();
    for (Object[] objs:list){
        System.out.println("name:"+objs[0]);
        System.out.println("tel:"+objs[1]);
        System.out.println("address:"+objs[2]);
        System.out.println("star:"+objs[3]);
    }
}

输出如下

Hibernate: 
    select
        sellerenti0_.name as col_0_0_,
        sellerenti0_.Id as col_1_0_,
        sellerenti0_.tel as col_2_0_,
        sellerenti0_.address as col_3_0_,
        sellerenti0_.star as col_4_0_,
        sellerenti0_.Id as Id1_4_,
        sellerenti0_.name as name2_4_,
        sellerenti0_.tel as tel3_4_,
        sellerenti0_.address as address4_4_,
        sellerenti0_.website as website5_4_,
        sellerenti0_.star as star6_4_,
        sellerenti0_.business as business7_4_ 
    from
        seller sellerenti0_
name:A服装店
tel:yang.entity.SellerEntity@3518e16c
address:13000000000
star:中国北京××区
name:B数码店
tel:yang.entity.SellerEntity@6900a87f
address:15800000000
star:中国浙江杭州市××区
name:C电器店
tel:yang.entity.SellerEntity@dac41fd3
address:13012341234
star:中国广东深圳市××区
name:D书店
tel:yang.entity.SellerEntity@1096d97d
address:18600000000
star:中国陕西西安市××区

也就是按没有用select字句和加上select字句的结果都有

正在回答

4 回答

查询语句中写错了,应该是s.tel 你写的是s,tel 这样,你在输出tel的时候,实际输出的是整个对象SellterEntity,后面的输出依次往后推,就出现了你看到的结果了。

0 回复 有任何疑惑可以回复我~

不知道是不是有什么隐藏机制

0 回复 有任何疑惑可以回复我~

话说查询的语句中有其他列的属性,但是输出结果中没有其他属性,,这不科学啊


0 回复 有任何疑惑可以回复我~

看不懂你的问题不知道你在说什么


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
HQL数据查询基础
  • 参与学习       41144    人
  • 解答问题       95    个

使用HQL从数据库中找到你要的数据,掌握了使用Hibernate

进入课程

select字句问题

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号