Anke Anke - 1 year ago 135
SQL Question

How can I execute a native SQL script in JPA/Hibernate?

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


I tried it this way:

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

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

Oracle Database 11g Express Edition Release - 64bit Production

Answer Source

Wrap your query with begin end block. Like

EntityManager manager = getEntityManager(); 
Query q = manager.createNativeQuery("BEGIN " + sqlScript + " END;");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download