Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate.hbm2ddl.import_files in persistence.xml is not working
    primarykey
    data
    text
    <p>I need that hibernate read a sql file before start junit tests, so I did the following configuration in persistence.xml:</p> <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt; &lt;persistence-unit name="test" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;properties&gt; &lt;property name="hibernate.connection.username" value="sa" /&gt; &lt;property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /&gt; &lt;property name="hibernate.connection.password" value="" /&gt; &lt;property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:9001/test" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /&gt; &lt;property name="hibernate.show_sql" value="true" /&gt; &lt;property name="hibernate.format_sql" value="true" /&gt; &lt;property name="hibernate.id.new_generator_mappings" value="true" /&gt; &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt; &lt;property name="hibernate.hbm2ddl.import_files" value="/META-INF/load.sql" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>The applicationContext.xml to load spring context:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt; &lt;context:component-scan base-package="com.test" /&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt; &lt;property name="persistenceUnitName" value="test" /&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"&gt;&lt;/tx:annotation-driven&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"&gt;&lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Junit tests extends the class:</p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/applicationContext.xml" }) @TestExecutionListeners(inheritListeners = false, listeners = { TransactionalTestExecutionListener.class, DependencyInjectionTestExecutionListener.class }) @TransactionConfiguration(defaultRollback = true) @Transactional public abstract class UnitTestConfiguration {} </code></pre> <p>When I run the junit tests, the file load.sql is not been imported and no errors are shown. I'm using Hibernate 4 and Spring 3.0.5.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload