Does anyone know how to configure h2 version 2.2.224 to drop in-memory 
tables between unit tests, or accept that they already exist?

The code in question runs a number of junit tests using an in-memory h2 
database. 
All of them fails to create the spring applicationcontext when I upgrade 
the h2-version past 1.4.199:

o.s.test.context.TestContextManager: Caught exception while allowing 
TestExecutionListener 
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener]
 
to prepare test instance [my testclass]
java.lang.IllegalStateException: Failed to load ApplicationContext

LocalContainerEntityManagerFactoryBean: Failed to initialize JPA 
EntityManagerFactory Unable to build Hibernate SessionFactory; nested 
exception is org.hibernate.exception.GenericJDBCException: Unable to open 
JDBC Connection for DDL execution
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: 
"java.lang.RuntimeException: object already exists" [50000-224]

I'm guessing that the problem lies in a failure to drop the tables created 
by the previous test class. 
I've tried all the tips I found at this link 
(https://blog.kie.org/2023/08/tip-h2-upgrade.html) and read through the 
available options for the constructor of the h2server, but I haven't found 
anything that allows the applicationContext to be created.

The tests are 
using "org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" as 
the jpaVendorAdapter 
of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.
This bean has properties:
        <property name="jpaProperties">
            <props>
                <prop 
key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.check_nullability">true</prop>
                <prop key="hibernate.id.new_generator_mappings">true</prop>
                <prop key="hibernate.jdbc.batch_size">100</prop>
                <prop 
key="hibernate.cache.use_second_level_cache">false</prop>
                <prop key="hibernate.order_inserts">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop 
key="javax.persistence.schema-generation.drop-source">script</prop> <-- 
tested based on the linked article
                <prop 
key="javax.persistence.schema-generation.drop-script-source">${project.basedir}/src/test/resources/drop-tables.sql</prop>
 
 <-- tested based on the linked article
            </props>
        </property>

The drop-tables.sql script contains 
DROP ALL OBJECTS

The h2server is defined with:
    <bean id="h2Server" class="org.h2.tools.Server" 
factory-method="createTcpServer" init-method="start" destroy-method="stop" 
depends-on="h2WebServer">
        <constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9092"/>
    </bean>

I've attempted to add the -ifNotExists option, with no effect.

The datasource:
    <bean id="dataSource" class="org.h2.jdbcx.JdbcDataSource">
        <property name="URL"
                  
value="jdbc:h2:mem:name;MODE=Oracle;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0;LOCK_TIMEOUT=60000;DB_CLOSE_ON_EXIT=FALSE"/>
        <property name="user" value="public"/>
    </bean>

I've tested MODE=LEGACY with no effect

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/03e2b050-e039-4714-85aa-ab94496b5c0fn%40googlegroups.com.

Reply via email to