How can I debug the processing of hibernate.hbm2ddl.import_files in combination with hsqldb?

In the Java project I'm working on, I have the following setup for our unit tests:

  • I use Spring Test MVC, @RunWith(SpringJUnit4ClassRunner.class) and @WebAppConfiguration to run unit tests, and I create an instance of MockMvc using webAppContextSetup(webApplicationContext) to test the application.
  • I have a Hibernate configuration to configure HSQLDB in memory, all tables are created based on @Entity classes.
  • In the Hibernate configuration, I set the hibernate.hbm2ddl.import_files property to load the import.sql file using SQL statements to populate the database (in memory).

Now I have confirmed all these works:

  • Tests can be successfully inserted / retrieved from the database in memory.
  • The SQL statements in import.sql are executed, as various tests confirm.

Now the problem . Errors that occur with the operators that I add to import.sql do not appear to be reported anywhere, none of the indications provided that an error occurred at all. Instead, subsequent statements are simply not executed. (I confirmed this by testing.)

Is there a way or to put these errors in messages that I apparently do not suspect? For this there is an additional property Hibernate?

Excerpt from sleep configuration:

  <bean id="sessionFactory" name="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.archive.autodetection">class,hbm</prop> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</prop> <prop key="hibernate.connection.username">sa</prop> <prop key="hibernate.connection.password"></prop> <prop key="hibernate.connection.url">jdbc:hsqldb:mem:myschema</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.hbm2ddl.import_files">configuration/test/import.sql</prop> <prop key="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor</prop> <!-- when using type="yes_no" for booleans, the line below allow booleans in HQL expressions: --> <prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop> </props> </property> </bean> 
+5
source share
2 answers

Not quite the answer to your question, but an alternative way to process a collection of test databases.

There is an XML namespace in Spring called jdbc that allows you to pre-populate your database with raw data at the start of the Spring context. It also reports great errors in your SQL queries:

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> <jdbc:initialize-database data-source="dataSource"> <jdbc:script location="org/mytestproject/schema-drop-hsqldb.sql" /> <jdbc:script location="org/mytestproject/schema-hsqldb.sql" /> <jdbc:script location="org/mytestproject/data-hsqldb.sql" /> </jdbc:initialize-database> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="validationQuery" value="${jdbc.validationQuery}"/> </bean> </beans> 
+1
source

You can enable logging in the org.hibernate.tool.hbm2ddl.SchemaExport class using the TRACE level.

Some errors are logged at the DEBUG level (for example, the file was not found):

 10:29:21,039 DEBUG SchemaExport:353 - Import file not found: ../myFile.sql 
0
source

All Articles