Class Account{     String accountno;
     
     Customer owner;
     ........
     }Class Customer{.....
}一个用户有多个account,一个account 只属于一个用户, 想通过 accountno 读取到customer 对象。
select a.owner from Account a   where  a.accountNo="+accountno;  不行请指教怎样写sql , 多谢

解决方案 »

  1.   

        你是想用hibernate 做吗???
    如果是的话,我正好有这个例子。[email protected]给我留言,我发给你。
      

  2.   

    是呀 , 那多谢 [email protected]
      

  3.   

    selcet * from User u where u.accout.accountno ="+accountno
      

  4.   

    你做的是单向关联把,在加一个<many-to-one>在account端实现多对一关联就行了
      

  5.   

    为什么要写出sql????在多的那一方配置一下多对一关系这样不就能拿到了吗?
      

  6.   

    做级联
    <many-to-one name="parent" column="parent_id" fetch="join"></many-to-one>private SshUser parent;
      

  7.   

    配置二个类对应的xx.hbm.xml
    Account.hbm.xml
    <many-to-one name="customer" class="Customer" fetch="select">
                <column name="accountno" precision="22" scale="0" />
            </many-to-one>
    Customer.hbm.xml....
                   <set name="account" inverse="true" lazy="false">
    <key>
    <column name="accountno" precision="22" scale="0"></column>
    </key>
    <one-to-many class="Account" />
    </set>
    ....
      

  8.   

    HQl 里面还能有* ???