简体   繁体   中英

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.

We are using Spring 4.0.2.RELEASE and hibernate 4.3.5.Final for development.

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:

eg

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

See if that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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