你可以看看HIBERNATE关于联合查讯的部分.我是菜鸟级的.

解决方案 »

  1.   

    customer 与 tb_domain是多对一吧?
    if (yes)
    {
        HQL : from Customer as c where c.tb_domain.domainid like   '%www.rytest14% '
    }
    else
    {
     sql = select   *   from   customer   where   customerid   in   (   select     customerid   from   tb_domain   where   domainid   like   '%www.rytest14% ')
    SQLQuery q = s.createSQLQuery(sql);
    }
      

  2.   

    from Customer where customerid in (select customerid from tb_domain where domainid like '%www.rytest14% ') 
      

  3.   

    to gosure:
    customer   与   tb_domain是多对一吧? 
    ============================
    不是,反过来
     customer 与 tb_domain是一对多的guan关系
    一个 customer可以有多个tb_domain正如现实中,一个人可以同时注册多个域名,但一个域名的注册者只能有一个
      

  4.   

    from   Customer   where   customerid   in   (select   customerid   from   tb_domain   where   domainid   like   '%www.rytest14%   ')
    =================================================
    org.hibernate.hql.ast.QuerySyntaxException: tb_domain is not mapped. [from com.ry800.webcs.hibernate.Customer where customerid in (select customerid from tb_domain where domainid like ?)]gougou8180 朋友的做法编译不过去,因为只简单的将customer改成 Customer
    后面还有tb_domain呢
      

  5.   

    语句好写,主要是看你映射文件怎么写了 from   Customer c  right join c.tb_domain c_t(注意:这是你在Customer 映射文件里的tb_domain的名字)where   c =c_t.customerid   and c_t.domainid   like '%www.rytest14%'大体就这么了吧,好久不用了,呵呵
    主要你把映射文件写好了
    hibernate的方便之处就在于写好映射文件以后就不用亲自处理表与表之间的关系了,你要还那么写还不如用原生sql了,写好映射文件就ok