Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute .sql script file in Hibernate JPA? [duplicate]

I have a SQL script with database dump. How can I execute it using Hibernate's EntityManager?

I tried it this way:

EntityManager manager = getEntityManager(); 
Query q = manager.createNativeQuery(sqlScript);
q.executeUpdate();

but it works only when sqlScript contains a single SQL query, while I need to run multiple inserts and other complex stuff.

RDBMS: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

like image 918
Anke Avatar asked Jan 16 '13 12:01

Anke


1 Answers

Wrap your query with begin end block. Like

EntityManager manager = getEntityManager(); 
Query q = manager.createNativeQuery("BEGIN " + sqlScript + " END;");
q.executeUpdate();
like image 190
hkutluay Avatar answered Nov 15 '22 04:11

hkutluay