Question

I want to fetch data from two tables using this query in hibernate:

select info.gwid,info.companyId,info.gwUserId,info.create_dt,stat.status,stat.lastactivity from gwinfo as info JOIN gwstatusinfo as stat ON info.gwid=stat.gwid

I tried like this hibernate:

Query query = session.createQuery("from SBoxInfo sinfo,SBoxStatus sstatus on sinfo.gwId = sstatus.gwId");
List<SBoxInfo> listOfSBoxs = (List<SBoxInfo>)query.list();

but it's not returning the list in SBoxInfo type. Do i have to create a criteria for that? How to create criteria for above query to retrieve the result in SBoxInfo type list?

Was it helpful?

Solution

Done by creating criteria like this:

Criteria ct = session.createCriteria(SBoxInfo.class);
ct.setFetchMode("SBoxStatus", FetchMode.JOIN);
List<SBoxInfo> listOfSBoxs = ct.list();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top