【问题标题】:Not Able to fetch table in Oracle Database after creating a table using JPA hibernate使用 JPA hibernate 创建表后无法在 Oracle 数据库中获取表
【发布时间】:2020-05-17 01:13:35
【问题描述】:

我正在尝试使用 Spring Boot 连接 Oracle Database 12c,并使用 JPA hibernate 创建一个表,并且代码在 postman get 和 post 工作正常(请求命中并创建表)中运行良好。现在,当我在我的 oracle 数据库 12c 中检查表时,我得到输出,因为表不存在。

这是我的数据库连接文件

    ## Database Properties
    #spring.datasource.url = jdbc:mysql://localhost:3306/detail?useSSL=false
    spring.datasource.url= jdbc:oracle:thin:@<IP>:1521/<pdb database service name>
    spring.datasource.username=sys as sysdba
    spring.datasource.password=Welcome1
    spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
    ## Hibernate Properties
    # The SQL dialect makes Hibernate generate better SQL for the chosen database
    spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
    # Hibernate ddl auto (create, create-drop, validate, update)
    spring.jpa.hibernate.ddl-auto=update
    server.port=8081
    spring.jpa.show-sql=true

这是我执行代码后的输出

    2020-01-31 16:06:40.916  WARN 7724 --- [  restartedMain] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 5006 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).
    2020-01-31 16:06:45.927  INFO 7724 --- [  restartedMain] com.example.DemoApplication              : Starting DemoApplication on Kirtis-Mac.local with PID 7724 (/Users/kirtijain/Downloads/demo/target/classes started by kirtijain in /Users/kirtijain/Downloads/demo)
    2020-01-31 16:06:45.927  INFO 7724 --- [  restartedMain] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
    2020-01-31 16:06:46.341  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
    2020-01-31 16:06:46.342  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
    2020-01-31 16:06:46.351  INFO 7724 --- [  restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface com.example.repository.UserRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.
    2020-01-31 16:06:46.351  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8ms. Found 0 JDBC repository interfaces.
    2020-01-31 16:06:46.358  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
    2020-01-31 16:06:46.359  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
    2020-01-31 16:06:46.365  INFO 7724 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6ms. Found 1 JPA repository interfaces.
    2020-01-31 16:06:46.506  INFO 7724 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$9bd21857] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2020-01-31 16:06:46.511  INFO 7724 --- [  restartedMain] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
    2020-01-31 16:06:46.523  INFO 7724 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    2020-01-31 16:06:47.870  INFO 7724 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
    2020-01-31 16:06:47.872  INFO 7724 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
    2020-01-31 16:06:47.873  INFO 7724 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.30]
    2020-01-31 16:06:47.950  INFO 7724 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
    2020-01-31 16:06:47.950  INFO 7724 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2016 ms
    2020-01-31 16:06:48.059  INFO 7724 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
    2020-01-31 16:06:48.076  INFO 7724 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Starting...
    2020-01-31 16:06:48.077  WARN 7724 --- [  restartedMain] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
    2020-01-31 16:06:53.326  INFO 7724 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Start completed.
    2020-01-31 16:06:53.326  INFO 7724 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
    Hibernate: create table test_table (id number(19,0) generated as identity, created_by varchar2(50 char) not null, created_date timestamp, email_address varchar2(255 char) not null, first_name varchar2(255 char) not null, last_modified_by varchar2(50 char), last_modified_date timestamp, last_name varchar2(255 char) not null, primary key (id))
    2020-01-31 16:07:02.689  INFO 7724 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
    2020-01-31 16:07:02.690  INFO 7724 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
    2020-01-31 16:07:02.699  INFO 7724 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
    2020-01-31 16:07:02.876  WARN 7724 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : 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
    2020-01-31 16:07:02.956  INFO 7724 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-01-31 16:07:03.142  INFO 7724 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path ''
    2020-01-31 16:07:03.142  INFO 7724 --- [  restartedMain] com.example.DemoApplication              : Started DemoApplication in 32.29 seconds (JVM running for 753.748)
    2020-01-31 16:07:03.144  INFO 7724 --- [  restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
    spring started 

Oracle 数据库中的结果

【问题讨论】:

  • 你通过邮递员得到什么?表格内容?你在正确的数据库上吗?运行 show table 命令。

标签: oracle hibernate spring-boot


【解决方案1】:

表在那里,因此您可能连接到错误的架构。你可以看到你所在的架构

show user

您可以通过

找出表在哪里查询数据字典
select table_name, owner from all_tables where table_name = 'test_table';

一个建议:在应用程序中以sys as sysdba 的身份连接是一种不好的做法。

您应该创建一个新架构(即 TEST)并使用这些凭据进行连接:除了安全方面(您的应用程序不能更改数据库中的所有内容)之外,您在指定的 Oracle 架构中默认创建表(和任何其他对象)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 2013-07-18
    • 2019-09-04
    • 2013-05-14
    相关资源
    最近更新 更多