How to execute sql script file using hibernate?

I am going to write some integration tests that will test interatcion with db. For each test, I need to have some db snapshot. Each db snapshot is saved in a .sql file. I want to execute a specific script file in a specific testing method, for example:

@Test
public void test_stuff(){
   executeScript(finame.sql);

   ... testing logic ...

   clean_database();
}

Does sleep mode have any means to do this?

+3
source share
4 answers
  • You can automatically execute the SQL script when you run hibernate: write your SQL commands in a file named import.sql and put it in the root of CLASSPATH.

  • , . , , . , Spring:

    @Transactional
    @TransactionConfiguration
    public class MyTest {
    ...
    }
    

Spring, .

+3

Session.connection()

+2

JDBC :

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#connection()

, executeScript(), hibernate, sql jdbc.

0

Hypersonic SQL? , , ( Read, update, insert, delete), , , . : http://www.hsqldb.org/

0
source

Source: https://habr.com/ru/post/1728612/


All Articles