簡體   English   中英

Spring Boot + JPA + Hibernate + Oracle在應用程序啟動期間不會自動創建表,並且日志中未報告任何錯誤

[英]Spring boot + JPA + Hibernate + Oracle does not auto create tables during application start and no errors reported in the log

我正在使用Oracle db作為數據存儲構建springboot應用程序。 我的應用程序在h2內存數據庫上運行良好,但是一旦將其定位到Oracle DB,它就無法按預期運行。 表不是在Oracle DB中創建的,但是我可以看到在應用程序啟動期間,SQL查詢已正確打印在控制台上。

我嘗試了spring.jpa.hibernate.ddl-auto屬性的所有可能性,但它們都不創建任何表。

我正在使用Springboot + JPA + Hibernate + Oracle數據庫。 在這里(pom.xml)我已注釋掉h2參考並添加了Oracle JDBC驅動程序。

<!--  dependency>            
    <groupId>com.h2database</groupId>            
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency-->
<dependency>
    <groupId>com.oracle.jdbc</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.4</version>
</dependency>

我的application.properties修改為具有url /用戶/密碼/驅動程序信息和方言信息。

spring.jpa.show-sql=true

spring.h2.console.enabled=true

#Using SID
spring.datasource.url= jdbc:oracle:thin:@somehost:1521:test
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

#hibernate configs
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=create

這是示例應用程序的開始輸出-

[INFO ] 2019-01-03 15:54:19.733 [main] RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
[INFO ] 2019-01-03 15:54:19.782 [main] RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 41ms. Found 1 repository interfaces.
[INFO ] 2019-01-03 15:54:20.019 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$bc3dc584] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[INFO ] 2019-01-03 15:54:20.261 [main] TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
[INFO ] 2019-01-03 15:54:20.364 [main] ContextLoader - Root WebApplicationContext: initialization completed in 1008 ms
[INFO ] 2019-01-03 15:54:20.387 [main] ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'formContentFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
Hibernate: drop table request cascade constraints
Hibernate: drop sequence hibernate_sequence
Hibernate: create sequence hibernate_sequence start with 1 increment by  1
Hibernate: create table request (id number(19,0) not null, creation timestamp, modification timestamp, request_data varchar2(32767), request_type varchar2(255 char), service_name varchar2(255), system_name varchar2(255), primary key (id))
[INFO ] 2019-01-03 15:54:28.276 [main] LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[INFO ] 2019-01-03 15:54:28.642 [main] ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
[WARN ] 2019-01-03 15:54:28.670 [main] JpaBaseConfiguration$JpaWebConfiguration$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 ] 2019-01-03 15:54:28.820 [main] TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''

應用程序啟動時會打印sql查詢,但實際上沒有一個在數據庫上執行。

我可以解決這個問題。 我直接在oracle db上運行生成的sql,發現列長度有問題。 我修改了值並構建了項目,然后可以看到該表已在數據庫中創建。

Spring Boot應用程序還有另一個問題,該表是在構建應用程序時而不是在應用程序啟動時創建的。 我將在論壇上發布另一個問題,以獲取有關此問題以及我面臨的其他一些問題的幫助。

您應該傳遞spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

比您的spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

但是,我不太確定有關Oracle DB的信息,它在Mysql上對我有用。 這不應該依賴於基礎數據庫IMO。

有關Spring Properties的更多選項,請查看此鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM