简体   繁体   English

如何使用休眠模式运行SQL脚本

[英]How to run SQL script using hibernate

I have a requirement to load and run a sql-script (ReportData_pr.sql) which will create some procedures on start-up and run those procedures. 我需要加载并运行sql脚本(ReportData_pr.sql),这将在启动时创建一些过程并运行这些过程。

We are using Spring 4.0.2.RELEASE and hibernate 4.3.5.Final for development. 我们正在使用Spring 4.0.2.RELEASE和Hibernate 4.3.5.Final进行开发。

Is it possible to run the script file by using hibernate. 是否可以使用休眠模式运行脚本文件。 If yes how to do that. 如果是的话,该怎么做。 If not is there any other work around to achieve my goal. 如果没有,那么可以完成我的目标。

Thanks 谢谢

You can run your script using nativequery: 您可以使用nativequery运行脚本:

eg 例如

EntityManager manager = getEntityManager(); 
Query q = manager.createNativeQuery("BEGIN"+sqlScript+"END;");
q.executeUpdate();

See if that helps 看看是否有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM