Tuesday, 6 August 2013

Hibernate Criteria to Join two tables to fetch data from both tables

Hibernate Criteria to Join two tables to fetch data from both tables

I have following scenario in which I want to fetch different columns from
two table into one entity: Entity 1: Table -> TBL_DISCUSSION public class
Discussion{ private int discussionId;// primary key private int
discussionText; private String createByUserId;// Foreign Key
(TBL_USER.userId) private String createByUserFullName;// This is just a
property, and does not have stored into table private Timestamp
createTimestamp; }
Entity 2: Table -> TBL_USER public class User{ private int userId;//
primary key private int userFullName; }
Now, what I need to do is that I have to fetch all the discussions from
TBL_DISCUSSION and also fetch UserFullName for every discussion creater
but we only store userId (createByUserId) into TBL_DISCUSSION table and
user's full name lies in TBL_USER table.
How, do I write a criteria to do achieve this?

No comments:

Post a Comment