简体   繁体   English

如何正确配置:spring boot/jpa/hibernate和oracle 19c

[英]How to properly configure: spring boot / jpa / hibernate and oracle 19c

I have strange problem.我有奇怪的问题。 I can't run my spring app when I change connection from MySQL to Oracle (19c).当我将连接从 MySQL 更改为 Oracle (19c) 时,我无法运行我的spring应用程序。 When I am using MySQL everything is fine.当我使用 MySQL 时一切正常。 My app is really simple, its doing nothing, it is sample empty project for test connection.我的应用程序非常简单,它什么都不做,它是用于测试连接的示例空项目。

Here is my application.properties (MySQL) :这是我的application.properties (MySQL)

spring.datasource.url=jdbc:mysql://localhost:3306/fckOracle
spring.datasource.username = root
spring.datasource.password = student
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver

and part of pom.xml (MySQL) ,pom.xml (MySQL) 的一部分

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <scope>runtime</scope>
</dependency>

Here is my application.properties (Oracle 19c)这是我的application.properties (Oracle 19c)

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=ALBERT
spring.datasource.password=student
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

and part of pom.xml (Oracle 19c)pom.xml 的一部分(Oracle 19c)

<dependency>
     <groupId>com.oracle.ojdbc</groupId>
     <artifactId>ojdbc8</artifactId>
</dependency>

Okay, when I am trying to run my app with oracle connection, compiler can't load dialect.好的,当我尝试使用 oracle 连接运行我的应用程序时,编译器无法加载方言。 Program is frozen and localhost:8080 doesn't work, and here is my console:程序被冻结并且 localhost:8080 不起作用,这是我的控制台: 在此处输入图片说明

I have tried a lot of dialects Oracle12cDialect, Oracle10gDialect ..., result is always the same, with one exception!我试过很多方言Oracle12cDialect、Oracle10gDialect ...,结果总是一样,只有一个例外! When I change the dialect to this:当我将方言更改为此时:

spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect

My app starts, but with error:我的应用程序启动,但出现错误:

java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

localhost8080 is working, but I cant do any operation on my oracle database. localhost8080 正在工作,但我无法对我的 oracle 数据库进行任何操作。

Anyone have idea how to fix this oracle configuration?有人知道如何修复这个 oracle 配置吗?

I have exact same issue, one thing that helps is to use old ojdbc8 driver for oracle DB, so replace your existing one with:我有完全相同的问题,有帮助的一件事是将旧的 ojdbc8 驱动程序用于 oracle DB,因此将现有驱动程序替换为:

<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>12.2.0.1</version>
</dependency>

But I would love to see the solution for newer drivers, because I have exact same problem and I have to use 19.3.0.0 drivers但我很想看到更新驱动程序的解决方案,因为我有完全相同的问题,我必须使用 19.3.0.0 驱动程序

Also about this error还有关于这个错误

java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist java.sql.SQLSyntaxErrorException: ORA-00942: 表或视图不存在

Try setting spring.jpa.hibernate.ddl-auto to update or create-drop .尝试将spring.jpa.hibernate.ddl-auto设置为updatecreate-drop This way Hibernate will generate schema and tables automaticaly and also drop them (when used create-drop ).这样 Hibernate 将自动生成模式和表,并删除它们(当使用create-drop )。 It is especially usefull, when you are still experimenting with model of your application.当您仍在试验应用程序模型时,它特别有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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