HIbernate - 外键查询失败

时间:2016-07-15 06:49:31

标签: mysql hibernate db2

请找到我的两张桌子

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.so_demo_frag,container,false);
    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400);
    v.setLayoutParams(p);
    return v;
}

CREATE TABLE "DBS_P2P"."KW_PAYMENT_IMAGEE_TEST"(IMAGE_KEY INTEGER PRIMARY KEY  NOT NULL GENERATED ALWAYS AS IDENTITY (  START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647  NO CYCLE CACHE 20 NO ORDER),REQUEST_ID INTEGER,IMAGE_CONTENT CLOB(5120000),FOREIGN KEY(REQUEST_ID) REFERENCES KW_PAYMENT_LINK_MASTER_TEST(REQUEST_ID))



CREATE TABLE "DBS_P2P"."KW_PAYMENT_IMAGEE_TEST"(IMAGE_KEY INTEGER PRIMARY KEY  NOT NULL GENERATED ALWAYS AS IDENTITY (  START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647  NO CYCLE CACHE 20 NO ORDER),REQUEST_ID INTEGER,IMAGE_CONTENT CLOB(5120000),FOREIGN KEY(REQUEST_ID) REFERENCES KW_PAYMENT_LINK_MASTER_TEST(REQUEST_ID))


<hibernate-mapping>
<class name="xyz" table="KW_PAYMENT_LINK_MASTER_TEST" catalog="xyz">
    <id name="requestId" type="int">
        <column name="REQUEST_ID"/>
        <generator class="identity"  />  
    </id>

    <property name="referenceWalletId" type="string">
        <column name="REFERENCE_ID"/>
    </property>

</class>

我能够插入但无法检索结果。

<hibernate-mapping>
<class name="com.kony.p2p.bo.KwPaymentImagetest" table="KW_PAYMENT_IMAGEE_TEST" catalog="DBS_P2P">

     <id name="imageKey" type="int">
        <column name="IMAGE_KEY"  />
        <generator class="identity" />  
    </id>

    <many-to-one name="KwPaymentLinkMastertest" class="com.kony.p2p.bo.KwPaymentLinkMastertest" fetch="select" lazy="false">
        <column name="REQUEST_ID" not-null="false"  />
    </many-to-one>

    <property name="imageContent" type="string">
        <column name="IMAGE_CONTENT" not-null="false" />
    </property>

</class>
<filter-def name="myFilter">

获得以下错误

org.hibernate.QueryException:无法解析属性:kwPaymentLinkMastertest:com.kony.p2p.bo.KwPaymentImagetest

请帮助修复

2 个答案:

答案 0 :(得分:2)

我认为你在这里打字错了。

<many-to-one name="KwPaymentLinkMastertest" with K is upper case
while Restrictions.eq("kwPaymentLinkMastertest" with k is lower case.

答案 1 :(得分:0)

雅    你是对的。

问题在于小写字母和大写字母,这有助于解决我的问题。

感谢。