I'm using a Spring MVC + JPA/Hibernate config over maven. When I deploy to Tomcat I expect Hibernate to execute an import.sql file but it doesn't matter where I put it or how I configure the path to the file, it never finds it.
org.hibernate.tool.hbm2ddl.SchemaExport SchemaExport - HHH000227: Running hbm2ddl schema export
org.hibernate.tool.hbm2ddl.SchemaExport SchemaExport - Import file not found: /META-INF/import.sql
My configuration for Hibernate is, in Spring:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.hbm2ddl.import_files">/META-INF/import.sql</prop>
</props>
</property>
</bean>
I'm using a standard Maven web folder structure, putting my import.sql
in the /src/main/webapp/WEB-INF/
folder. I also tried removing the import_files
property and putting it in the webapp
folder to no avail.
I suspect it can be something related to the tomcat policy of mapping web.jar
urls against server_root/web/*
.
The import.sql
is read from the root of the classpath. In a maven project src/main/webapp
isn't the classpath but the web content. The classpath consists of the java classes in src/main/java
and additonal non java things in src/main/resources
.
Putting your import.sql
into the src/main/resources
will let hibernate load it. As when constructing the jar the content of this directory is copied to WEB-INF/classes
which in a web application is part of the classpath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With