I am newbie to Hibernate.
I am following hibernate mapping
<hibernate-mapping>
<class name="com.amp.rfq.AltPartView" table="MYTEST_BA_ALT_PART_V">
<id name="id" column="RFQ_ID">
<generator class="native"/>
</id>
<property name="combinationId" column="COMBINATION_ID"/>
<property name="altPartNo" column="PART_NO"/>
<property name="partNo" column="ALT_PART_NO"/>
<property name="mfg" column="MFG"/>
<property name="genPartNo" column="GEN_PART_NO"/>
</class>
</hibernate-mapping>
and the data in the datanase table looks something like
RFQ_ID,COMBINATION_ID,PART_NO,ALT_PART_NO,MFG,GEN_PART_NO
457177,775107,LM339ADT,LM339AD,STM
457177,775109,LM339ADT,LM339AD,ONS
457177,775110,LM339ADT,LM339ADR,ONS
When I use following code to get these three rows
List result = HibernateUtil.getSessionFactory()
.getCurrentSession().createCriteria(AltPartView.class)
.add(Restrictions.eq("id", Long.valueOf(457177)))
.list();
out.println("<h2>RFQ Id "+ rfqid +" Size is "+result.size()+" list "+result+" </h2>");
if (result.size() > 0) {
out.println("<h2>Alternates in database:</h2>");
out.println("<table border='1'>");
out.println("<tr>");
out.println("<th>Id</th>");
out.println("<th>Combination No</th>");
out.println("<th>Part No</th>");
out.println("<th>Alt Part No</th>");
out.println("<th>Mfg</th>");
out.println("<th>Gen Part No</th>");
out.println("</tr>");
for (Iterator it = result.iterator(); it.hasNext();) {
AltPartView altPartView = (AltPartView) it.next();
out.println("<tr>");
out.println("<td>" + altPartView+ "</td>");
out.println("<td>" + altPartView.getCombinationId()+ "</td>");
out.println("<td>" + altPartView.getPartNo()+ "</td>");
out.println("<td>" + altPartView.getAltPartNo() + "</td>");
out.println("<td>" + altPartView.getMfg() + "</td>");
out.println("<td>" + altPartView.getGenPartNo() + "</td>");
out.println("</tr>");
}
out.println("</table>");
}
I get following result
RFQ Id 457177 Size is 3 list [com.amp.rfq.AltPartView@14a75bb, com.amp.rfq.AltPartView@14a75bb, com.amp.rfq.AltPartView@14a75bb]
Alternates in database:
Id Combination No Part No Alt Part No Mfg Gen Part No
com.amp.rfq.AltPartView@14a75bb 775107 LM339AD LM339ADT STM null
com.amp.rfq.AltPartView@14a75bb 775107 LM339AD LM339ADT STM null
com.amp.rfq.AltPartView@14a75bb 775107 LM339AD LM339ADT STM null
I get first row for all three records. I am struggling with this for some time now without any success. Could somebody please help me.
|