简体   繁体   中英

spring.jpa.hibernate.ddl-auto=update not working in spring boot

I am integrating spring boot + jpa + oracle. I was successful in creating and drop the database with spring.jpa.hibernate.ddl-auto=create-drop , but when I change the property to spring.jpa.hibernate.ddl-auto=update , spring boot hangs up and the application is not starting up.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.1.RELEASE)

2021-01-03 00:54:49.024  INFO 40612 --- [           main] com.walmart.DemoApplication     : Starting DemoApplication on m-c02dj138ml85 with PID 40612 (/Users/b0j02tw/Documents/demo/target/classes started by b0j02tw in /Users/b0j02tw/Documents/demo)
2021-01-03 00:54:49.026  INFO 40612 --- [           main] com.walmart.DemoApplication     : No active profile set, falling back to default profiles: default
2021-01-03 00:54:49.325  INFO 40612 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2021-01-03 00:54:49.367  INFO 40612 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 35ms. Found 1 JPA repository interfaces.
2021-01-03 00:54:49.656  INFO 40612 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-03 00:54:49.684  INFO 40612 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-01-03 00:54:49.719  INFO 40612 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.17.Final
2021-01-03 00:54:49.733  INFO 40612 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2021-01-03 00:54:49.823  INFO 40612 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2021-01-03 00:54:49.891  INFO 40612 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-01-03 00:54:53.118  INFO 40612 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-01-03 00:54:53.148  INFO 40612 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect

application.properties :

#==== Looging properties ======#
#debug=true
#==== Looging root levels - TRACE, DEBUG, INFO, WARN, ERROR, OFF ======#
logging.level.root=INFO


spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
##===== START - OracleDB connection settings ======#
spring.datasource.url=jdbc:oracle:thin:@//****
spring.datasource.username=***
spring.datasource.password=******
spring.jpa.hibernate.ddl-auto=update
##===== END - OracleDB connection settings ======#
#

##====== START - JPA settings ======

##===== END - OracleDB connection settins ======#
#

#SQL FOR DEBUGGING
spring.jpa.show-sql=true

This could be a comment but its kind of tool long for the comment so I post this as an answer. Here are some ideas that can point you on the right direction:

Idea 1

When you use update as this property value - a lot of things actually happen, way more than drop-create . In fact Java tries to read a lot of "meta-data" about your schema and adjust the tables in accordance with the mapping defined in JPA/Hibernate.

For more details, make sure, you're reading this SO thread . BTW after reading the answer that explains in details what happens when you set this property to be update - maybe you'll come to conclusion that you don't really need it;)

Long story short, its possible (and this is just a guess) that your application is really "doing" something in a background, some time consuming operations that can take quite a while. So try to take a thread dump and check whether you see any "running" threads.

Idea 2

Another possible reason is that you don't have permissions to read metadata/any other operation (it really depends on how exactly you've set up your Oracle Database). The mitigation is hard to describe here - probably you should see what happens with the DBA or something, there might be really a lot of reasons for getting stuck in java, or maybe there is a lock - who knows.

Idea 3

You might also want to log the SQL commands that your spring boot application runs upon the start. Its possible to enable tracing for oracle driver (at the level of the driver), at the level of hibernate / spring, etc. So again, think about this direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM