Shruti sharma
Shruti sharma

Reputation: 211

Not able to connect spring jpa with Oracle

Hi I am using below configuration still I am getting error.

spring.datasource.url=jdbc:oracle:[email protected]:1521:mfg1229
spring.datasource.username=apps
spring.datasource.password=xxxx
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=Oracle12cDialect

below dependency i used in pom.xml

    <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
             <scope>runtime</scope>
   </dependency>

still I am getting below error.

Caused by: java.lang.ClassNotFoundException: Could not load requested class : Oracle12cDialect
    at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210) ~[hibernate-core-5.4.23.Final.jar:5.4.23.Final]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
    at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
    at java.base/java.lang.Clas?s.forName(Class.java:427) ~[na:na]
    enter code here

    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:130) ~[hibernate-core-5.4.23.Final.jar:5.4.23.Final]
    ... 28 common frames omitted

WHat is the problem in my configuration. instead of driver-class i also checked with driver-class-name I checked OracleDialect, Oracle10gDialect and Oracle12cDialect . for all the 3 i am getting same error.

Upvotes: 2

Views: 1813

Answers (2)

priyranjan
priyranjan

Reputation: 704

there is nothing like "Oracle12cDialect" dialect. you need to write in proper way. :--

in your property file it is:

spring.jpa.properties.hibernate.dialect=Oracle12cDialect
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:[email protected]:1521:mfg1229

but it should be:--

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin@//sca00tof.us.dell.com:1521/mfg1229

if does not work then please change to:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

Upvotes: 4

Marcinek
Marcinek

Reputation: 2117

The dialect for Oracle12c can be use with hibernate 5.x.

You should add this to your classpath:

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.24.Final</version>
</dependency>

Please note that you need the dialect for the coreesponding Version of Oracle DB.

How ever I can't see the exact framework you are using. Please check that the obove dependency is part of your classpath. This may come with other dependencies such as JPA oder spring-data.


Also please note that your jdbc string seems to be wrong.

It should look like this:

url="jdbc:oracle:thin:@sca00tof.us.dell.com:1521:mfg1229"

See here for details: URL string format for connecting to Oracle database with JDBC

Upvotes: 2

Related Questions