Hi,
I am new to Hibernate, I tried to do a join b/w two tables(User & Role) I got the resultant list of objects.. but I am not able to retrieve the corresponding objects and fileds from the resultant list of objects. According to our db design specification there should not be foreign key relation b/w User and Role in db level.
The source code:
User.hbm.xml:
-------------------
<hibernate-mapping package="com.sample.hiber">
<class name="User" table="users">
<id name="logonId" column="logonId" type="string"
length="20" >
<generator class="assigned"/>
</id>
<property name="roleId" type="string" length="20"/>
<property name="name" type="string" length="40"/>
<property name="password" type="string" length="20"/>
<property name="emailAddress" type="string" length="40"/>
<property name="lastLogon" type="date"/>
</class>
</hibernate-mapping>
Role.hbm.xml:
-----------------
<hibernate-mapping package="com.sample.hiber">
<class name="Role" table="roles">
<id name="roleId" column="roleId" type="string" length="20">
<generator class="assigned"/>
</id>
<property name="description" type="string" length="40"/>
</class>
</hibernate-mapping>
The above two are mappings for User and Role table.
How to achive the below specified sql query using HQL...?
"select usr.name, usr.emailAddress, rol.description from users as usr, roles as rol where usr.roleId=rol.roleId" (This is the normal SQL).
I tried as below:
------------------
Query usrQuery = session.createQuery("select usr, rol from User as usr, Role as rol where usr.roleId=rol.roleId");
List lst_users = usrQuery.list();
for (Iterator it = lst_users.iterator(); it.hasNext();)
System.out.println("Test:" + it.next().toString() );
Output:
---------
Test:[Ljava.lang.Object;@6cc26cc2
Test:[Ljava.lang.Object;@6ebb6ebb
I am unable to find what class type is this and how to retieve the fields of User and Role from this resultant list ?
Thanku for your time..
Regards,
-Jags
_________________ In a world without fences, who needs GATES??
|