SELECT emp.employeeId, emp.employeeFirstName, comp.companyname, dept.departmentname
FROM Employeetable emp, Companytable comp, departmenttable dept
WHERE emp.employeeCompanyId=comp.companyId AND emp.EmployeeDepartmentID=dept.DepartmentID;
The employeetable hbm file:
<sql-query name="callrealtimeprocedure">
<return alias="employeetable" class="com.AdiSys.eRMS.entity.Employeetable"/>
<return-join alias="companytable" property="com.AdiSys.eRMS.entity.Employeetable"/>
<return-join alias="companytable" property="com.AdiSys.eRMS.entity.Employeetable"/>
</sql-query>
The employeetable pojo:
@NamedNativeQueries({
@NamedNativeQuery(
name = "callrealtimeprocedure",
query = "CALL realtime(:employeeId,:employeeFirstName)",
resultClass = Employeetable.class
)
})
@Entity
Similarly department hbm and pojo.
My java class after creating session:
Query EmplyeeQuery = session.createSQLQuery("CALL realtime(:employeeId,:employeeFirstName,:companyname,:departmentname)")
.addEntity(Employeetable.class)
.addEntity(Companytable.class)
.addEntity(Departmenttable.class)
.setParameter("employeeId", "")
.setParameter("employeeFirstName","")
.setParameter("companyname", "")
.setParameter("departmentname", "");
I'm not able to find out how to link up stored procedure sql query in hbm and pojo and java class