请教一个问题:
在用hibernate的时候,由于数据库的设计的关系,不能变更
表1   table1
column1
column2
column3
column4
....
columnn表2  table2
columna
columnb
columnc
columnd
....
columnz
他们只是一些log表,没有关键字。
现在如果我要实现这样的目的,请教 mapping应该怎么配置
from table1,table2 where table1.column1 = table2.columna and table1.column3 = table2.columnb
不用hql,直接用QBC,找了很多资料,多是关于关键字关联的。

解决方案 »

  1.   

    非主键关联
    随便找了一个
    http://hi.baidu.com/piao_live/blog/item/9fa786d02706168aa0ec9ce9.htmlhibernate many to one 非主键关联hibernate在默认情况下,从表跟主表的关联,是通过主键来关联的,但是如果双方关联的字段都不是主键的情况下,可以在<many-to-one 这方设置一下property-ref,这样就可不通过主键来关联,例如:ListCommon(是<many-to-one方)的listMemberSid字段,要跟Broker(是<one-to-many方)表的brokMemberSid字段关联,只要在ListCommon的xml中加入property-ref=“brokMemberSid”,这样就等于说明了ListCommon表是通过Broker表的brokMemberSid属性来跟Broker来关联的,如下:。Broker.hbm.xml..........<hibernate-mapping package="com.crb2b.data.bo">
        <class name="Broker" table="crb2b_broker" >
            <id name="brokId" type="java.lang.Integer">
                <column name="brokId" />
                <generator class="native"></generator>
            </id><property name="brokMemberSid" type="java.lang.String">
                <column name="brokMemberSid" length="11" not-null="true" />
            </property><set
                name="crb2bListcommons"
                lazy="false"             
                inverse="true"
                cascade="all"  
                >
                <key>
                    <column name="listMemberSid"    length="11" not-null="true" />
                </key>
                <one-to-many class="ListCommon" />
            </set>...................ListCommon.hbm.xml:<hibernate-mapping package="com.crb2b.data.bo">
        <class name="ListCommon" table="crb2b_listcommon" >
            <id name="licoId" type="java.lang.Integer">
                <column name="licoId" />
                <generator class="native"></generator>
            </id>
            
            <many-to-one name="crb2bBroker" class="Broker" fetch="select" property-ref="brokMemberSid">
                <column name="listMemberSid" length="11" not-null="true" />
            </many-to-one>       。。