I have two table,table A and table B,
table A
Code:ID NAME --------------- test John tiger Kate
table B
Code:ID USERID DESCRIPTION ----------------------- b1 test this is a test b1 tiger this is a tiger b2 abc this is a abc
A.hbm.xml
B.hbm.xmlCode:<class name="AModel" table="A"> <id name="id" column="id" type="java.lang.String"> <generator class="assigned"/> </id> <property name="uname" type="java.lang.String"> <column name="name" length="18" not-null="true" /> </property> </class>
Code:<class name="BModel" table="B"> <id name="id" column="id" type="java.lang.String"> <generator class="assigned"/> </id> <property name="uid" type="java.lang.String"> <column name="userid" length="100" not-null="false" /> </property> <property name="g" type="java.lang.String"> <column name="description" length="100" not-null="false" /> </property> </class>
AModel.java
Code:public class AModel{ private String id; private String uname; .... }
BModel.java
Code:public class BModel{ private String id; private String uid; private String g; .... }
Then I execute following statement:
It should print following result:Code:List info=this.getHibernateTemplate().find("from AModel a,BModel b where b.uid=a.id and b.id=?",'b1'); AModel a; BModel b; if(info.size()>0){ for(int i=0;i<info.size();i++){ Object[] obj=(Object[])info.get(i); for(int j=0;j<obj.length;j++){ (obj[j] instanceof BModel){ b=(BModel)obj[j]; System.out.print(b.getUid()); System.out.print(b.getG()); } if(obj[j] instanceof AModel){ a=(AModel)obj[j]; System.out.println(a.getUname()); } System.out.println(""); }
Code:test John this is a test tiger Kate this is a tiger
above result is the result which I wish to get! But it prints following error result:
Code:test Kate this is a tiger tiger Kate this is a tiger
I don't know why it show correct result? I am puzzled it for several days! Anyone could point out where wrong with me?
How to get correct my code to get correct result:
Code:test John this is a test tiger Kate this is a tiger
Thanks!


Reply With Quote