У меня есть проект SpringBoot с БД Oracle, и для тестов я использую H2 в памяти db с create-drop
.При использовании Oracle 10g или 12c диалект, я получаю исключения, когда он пытается отбросить таблицы во время запуска.Если я использую диалект H2dialect или Mysql5, исключений не будет.
Я использую Ojdbc7, совместимый с диалектом Oracle 10g или 12c и Hibernate 5.3.7.
My application-test.xml
spring:
profiles:
active: all, mock-authentication
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:testdb
username: air
password: carrier
driver-class-name:
jpa:
hibernate.ddl-auto: create-drop
database-platform: org.hibernate.dialect.Oracle12cDialect
liquibase:
enabled: false
Мои тестовые классы имеют следующую конфигурацию:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SomeIntegrationApplication.class)
@AutoConfigureMockMvc
@AutoConfigureTestDatabase
@TestPropertySource(properties = {
PASSWORD_PROPERTY,
})
@ActiveProfiles({"test"})
public class SearchResourceTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private SearchService searchService;
@Test
public void getSomething() throws Exception {
.....// My test cases follows
В моем пути к классам data.sql
с операторами вставки.
С диалектом oracle10g или 12c я получаюследующие исключения предупреждений, но все тестовые случаи пройдены
INFO [-,,,] 19524 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
INFO [-,,,] 19524 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
INFO [-,,,] 19524 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
INFO [-,,,] 19524 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
INFO [-,,,] 19524 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
INFO [-,,,] 19524 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
INFO [-,,,] 19524 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.OracleDialect
2WARN [-,,,] 19524 --- [ main] org.hibernate.dialect.Oracle9Dialect : HHH000063: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
WARN [-,,,] 19524 --- [ main] org.hibernate.dialect.OracleDialect : HHH000064: The OracleDialect dialect has been deprecated; use Oracle8iDialect instead
WARN [-,,,] 19524 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "drop table air_leg cascade constraints" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table air_leg cascade constraints" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "AIR_LEG" not found; SQL statement:
drop table air_leg cascade constraints [42102-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.command.ddl.DropTable.prepareDrop(DropTable.java:71)
at org.h2.command.ddl.DropTable.update(DropTable.java:129)
at org.h2.command.CommandContainer.update(CommandContainer.java:133)
at org.h2.command.Command.executeUpdate(Command.java:267)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:233)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 60 common frames omitted
Эти исключения происходят для каждой дБ таблицы, присутствующей в моем db.changelog-master.yaml
После исключений h2 загружает мои data.sql
данные следующим образом:
INFO [-,,,] 19524 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@24caa80'
INFO [-,,,] 19524 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
WARN [-,,,] 19524 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
INFO [-,,,] 19524 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO [-,,,] 19524 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 05dbb5f7-a9e8-45db-bd33-8f3772c6f033
INFO [-,,,] 19524 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6b5f91a5, org.springframework.security.web.context.SecurityContextPersistenceFilter@7083e548, org.springframework.security.web.header.HeaderWriterFilter@319c77de, org.springframework.security.web.authentication.logout.LogoutFilter@254dfd34, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@43b1fdb7, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5c14c284, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@375dc95c, org.springframework.security.web.session.SessionManagementFilter@5acbef42, org.springframework.security.web.access.ExceptionTranslationFilter@5ab45d66, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2d1dbf4f]
INFO [-,,,] 19524 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
INFO [-,,,] 19524 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
DEBUG [-,,,] 19524 --- [ main] c.s.i.w.TraceSpringDataBeanPostProcessor : Wrapping bean [restHandlerMapping] of type [DelegatingHandlerMapping] in its trace representation
INFO [-,,,] 19524 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
INFO [-,,,] 19524 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
INFO [-,,,] 19524 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
INFO [-,,,] 19524 --- [ main] c.k.t.a.config.DatabaseSetupController : Init database form file /data.sql
INFO [-,,,] 19524 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
INFO [-,,,] 19524 --- [ main] c.k.t.a.config.DatabaseSetupController : delete from CB_USERS
INFO [-,,,] 19524 --- [ main] c.k.t.a.config.DatabaseSetupController : delete from AIRPORTS
INFO [-,,,] 19524 --- [ main] c.k.t.a.config.DatabaseSetupController : delete from LOGICAL_ADD
INFO [-,,,] 19524 --- [ main] c.k.t.a.config.DatabaseSetupController : INSERT INTO LOGICAL_ADD (ID,LOGICAL_SEND,IATAS,CASSS,STATIONS,LH_CBDD,AFKL_CUSTOMER_ID) VALUES (1,'ABCR07','5510067','0015','COR',NULL,NULL)
После этого все тестовые примеры проходят без каких-либо исключений.Если я изменю диалект на org.hibernate.dialect.H2Dialect
или MySQL5Dialect
, то больше не будет исключений для предупреждений.Поскольку я использую Oracle DB в производственной среде, я хочу использовать оракул, но не смог избежать неприятностей с исключениями предупреждений.
Любая идея, почему H2 ведет себя странно или выдает исключения из таблицы пропусков при использовании OracleДиалект 10г или 12с?