Java: Hibernate don’t import files

my Hibernate Config doesn’t import any .sql files. The files are located in src/test/resources and the Source in src/test/java.

The Part of the Config:

Configuration configuration = new Configuration();
Properties p = new Properties();
p.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
p.put("hibernate.connection.driver_class", "org.h2.Driver");
p.put("hibernate.connection.url", "jdbc:h2:mem:test");
p.put("hibernate.show_sql", "true");
p.put("", "create-drop");
p.put("hibernate.hbm2ddl.import_files", "/createdb.sql");
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(p).build();
this.sf = configuration.buildSessionFactory(serviceRegistry);

I don’t know why he doesn’t import the .sql file. I hope that anyone can help me.



As per the link hibernate.hbm2ddl.import_files: Path to the files

The path needs to be pathed as

<prop key="hibernate.hbm2ddl.import_files">/WEB-NF/resources/createdb.sql</prop>

or programmatically as

p.put("hibernate.hbm2ddl.import_files", "/WEB-INF/resources/createdb.sql");

Leave a Reply

Your email address will not be published. Required fields are marked *