![](/img/trans.png)
[英]Hibernate-Spring boot : spring.jpa.hibernate.ddl-auto=update recreates tables and columns after update the entity
[英]spring.jpa.hibernate.ddl-auto=update not working in spring boot
我正在集成 spring 引导 + 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没有启动。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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
这可能是一条评论,但它是一种很适合评论的工具,所以我将其发布为答案。 以下是一些可以为您指明正确方向的想法:
理念一
当您使用update
作为此属性值时-实际上会发生很多事情,而不仅仅是drop-create
。 事实上,Java 尝试读取有关您的架构的大量“元数据”,并根据 JPA/Hibernate 中定义的映射调整表。
有关更多详细信息,请确保您正在阅读此 SO 线程。 顺便说一句,在阅读详细解释了当您将此属性设置为update
时会发生什么的答案后 - 也许您会得出结论,您并不真的需要它;)
长话短说,您的应用程序可能(这只是一个猜测)确实在后台“做”某事,一些耗时的操作可能需要相当长的时间。 因此,尝试进行线程转储并检查您是否看到任何“正在运行”的线程。
想法 2
另一个可能的原因是您没有读取元数据/任何其他操作的权限(这实际上取决于您设置 Oracle 数据库的准确程度)。 缓解在这里很难描述——也许你应该看看 DBA 发生了什么,可能有很多原因会卡在 java 中,或者可能有锁——谁知道呢。
想法 3
您可能还想记录 spring 启动应用程序在启动时运行的 SQL 命令。 可以在 hibernate / spring 等级别启用对 oracle 驱动程序(在驱动程序级别)的跟踪。所以再想想这个方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.