开发者

Not able to fetch property using Criteria and Projection

开发者 https://www.devze.com 2023-04-05 19:07 出处:网络
<id name=\"id\" type=\"java.lang.Long\"> <column name=\"MBR_ATR_ID\"/> <generator class=\"sequence\">
      <id name="id" type="java.lang.Long">
            <column name="MBR_ATR_ID"/>
            <generator class="sequence">
                <param name="sequence">ESPMB.MBR_ATR_ID_SEQ</param>
            </generator>
        </id>

        <property name="memberId" type="long">
            <column name="MBR_ID" length="18"/>
        </property>
        <property name="customerId" type="long">
            <column name="CUST_ID" length="18"/>
        </property>
        <property name="eligibilitySourceSystem" type="string">
            <column name="ELIG_SRC_SYS" length="20" not-null="true"/>
        </property>

above HBM file belongs to MemberAttribute.hbm file and memberId is foreign key and it is  primary key in Member.hbm file.

Projection projection = Projections.projectionList()
        .add(Property.forName("memberId"))
        .add(Property.forName("customerId"));
memberAttributeCriteria.setProjection(projection);
 List<Object> results =  memberAttr开发者_如何学JAVAibuteCriteria.list();
Iterator iter = results.iterator();
while (iter.hasNext())
        {
            System.out.println("New object");
            Object[] obj = (Object[]) iter.next();
            for (int i=0;i<obj.length;i++)
            {
                System.out.println(obj[i]);  // memberId always coming as null. 
            }


        }

MemberId is always coming as null. can anyone help on this?


It's happened because you have no relation between Member entity and this. If you wont to get relation using hibernate you must define this relation in your orm.xml.

for example:

<one-to-one name="memberId" target-entity="path.to.entiny.Member">
     <join-column name="ID" referenced-column-name="id"/>
</one-to-one>
0

精彩评论

暂无评论...
验证码 换一张
取 消