问题描述
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;
可设置的hbm文件:
< sql-query name =callrealtimeprocedure>
< return alias =employeetableclass =com.AdiSys.eRMS.entity.Employeetable/>
< return-join alias =companytableproperty =com.AdiSys.eRMS.entity.Employeetable/>
< return-join alias =companytableproperty =com.AdiSys.eRMS.entity.Employeetable/>
< / sql-query>
可设置的pojo:
@NamedNativeQueries({
@NamedNativeQuery(
name =callrealtimeprocedure,
query =CALL realtime(:employeeId,:employeeFirstName ),
resultClass = Employeetable.class
)
})
@Entity
类似部门hbm和pojo。
创建会话后的我的java类:
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,);
我无法知道如何连接hbm和pojo中的存储过程sql查询, java class
好吧,首先,我不会对存储过程感到困扰。使用Hibernate的重点是你不需要编写任何SQL。如果你要编写SQL,那么使用Hibernate就没有多少好处。
Hibernate文档的一个非常好的来源是 - 如果您选择任何版本的Hibernate的核心参考手册,您会发现一些关于如何设置POJO的非常好的示例。
另外,我不知道您是否打算使用Hibernate注释。我喜欢这些 - 它们比使用单独的XML文件要少得多。查看Hibernate注释参考指南(来自v3.5下的相同链接),以获取使用它们的指导。
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
Well, for a start, I wouldn't have bothered with the stored procedure. The whole point of using Hibernate is that you don't need to write any SQL. If you're going to write SQL, then there's not much to be gained by using Hibernate.
A really good source of Hibernate documentation is http://www.hibernate.org/docs - if you go to the "Core Reference Manual" for whichever version of Hibernate you have, you'll find some really good examples on how to set up your POJOs.
Also, I don't know if you're planning to use Hibernate annotations. I like these - they're a lot less messy than using separate XML files. Have a look at the "Hibernate Annotations Reference Guide" (from the same link, under v3.5) for guidance on using them.
这篇关于如何在hibernate hbm文件和pojo以及java类中使用多个表调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!