select * from shop inner join shoptype on shop.shopTYPEid = shoptype.shoptypeid where shoptype.shoptypeShort = 'COMPUTERS'Shop.hbm.xml<hibernate-mapping>
<class name="com.bank.bean.Shop" table="Shop">
<id name="shopId" column="ShopId" type="int">
<generator class="identity"></generator>
</id>

<property name="shopName" type="string"/>
<property name="shopPrice" type="float"/>
<property name="shopStock" type="int"/>
<property name="shopScores" type="int"/>
<property name="shopTime" type="date"/>
<many-to-one name="shopClass" column="ShopTypeId" class="com.bank.bean.ShopType" lazy="false"/>
</class>
</hibernate-mapping>ShopType.hbm.xml<hibernate-mapping>
<class name="com.bank.bean.ShopType" table="ShopType">
<id name="shopTypeId" column="shopTypeId" type="int">
<generator class="identity"/>
</id>
<property name="shopTypeName" type="string"/>
<property name="shopTypeShort" type="string"/>

<set name="shop" cascade="all" inverse="true" lazy="true">
<key column="shopTypeId"/>
<one-to-many class="com.bank.bean.Shop"/>
</set>
</class>
</hibernate-mapping>
如果我想得到shopType.shopTypeShort这个列的数据..在daoImpl应该怎么写HQL语句??
String hql="from Shop where shopTypeShort=?";
List<Shop> list = getHibernateTemplate().find(hql,new String[]{bean.getShopClass().getShopTypeShort()});
bean = list.size()!=0?list.get(0):null; 

return list;它说 shopTypeShort这个列无效..我明明是连了关系.应该按道理说查Shop这表的时候查出ShopType的数据的吧

解决方案 »

  1.   

    不记得说我是条件查询的.public List<Shop> findAll(Shop bean) {
    Shop shop = new Shop();
    System.out.println(bean.getShopClass().getShopTypeShort()+"  简称");
    String hql="from Shop where shopTypeShort=?";
    List<Shop> list = getHibernateTemplate().find(hql,new String[]{bean.getShopClass().getShopTypeShort()});
    bean = list.size()!=0?list.get(0):null; 

    return list;
    }
    我想查ShopType表中的ShopTypeShort列数据..请问HQL怎么写!谢谢
    谢谢
    谢谢
      

  2.   

    from Shop s where s.shopTypeShort=?
      

  3.   

    应该是:from Shop s where s.ShopType.ShopTypeShort=?
      

  4.   

    from Shop s where s.ShopType.ShopTypeShort=?
      

  5.   

    from 表名 where 查询条件
      

  6.   

    select shop.ShopTypeShort from ShopType shop