2

I am building springboot application with Oracle db as a datastore. My application works fine with h2 inmemory database but as soon as I target it to Oracle DB it does not work as expected. Tables are not created in Oracle DB but I can see that sql queries are properly printed on the console during application startup.

I tried all possibilities for property spring.jpa.hibernate.ddl-auto and all of them do not create any table.

I am using Springboot + JPA + Hibernate + Oracle database. Here(pom.xml) I have commented out h2 reference and added Oracle JDBC driver.

<!--  dependency>            
    <groupId>com.h2database</groupId>            
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency-->
<dependency>
    <groupId>com.oracle.jdbc</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.4</version>
</dependency>

My application.properties is modified to have url/user/password/driver info and dialect info.

spring.jpa.show-sql=true

spring.h2.console.enabled=true

#Using SID
spring.datasource.url= jdbc:oracle:thin:@somehost:1521:test
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

#hibernate configs
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=create

Here is a sample application start output -

[INFO ] 2019-01-03 15:54:19.733 [main] RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
[INFO ] 2019-01-03 15:54:19.782 [main] RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 41ms. Found 1 repository interfaces.
[INFO ] 2019-01-03 15:54:20.019 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$bc3dc584] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[INFO ] 2019-01-03 15:54:20.261 [main] TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
[INFO ] 2019-01-03 15:54:20.364 [main] ContextLoader - Root WebApplicationContext: initialization completed in 1008 ms
[INFO ] 2019-01-03 15:54:20.387 [main] ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'formContentFilter' to: [/*]
[INFO ] 2019-01-03 15:54:20.390 [main] FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
Hibernate: drop table request cascade constraints
Hibernate: drop sequence hibernate_sequence
Hibernate: create sequence hibernate_sequence start with 1 increment by  1
Hibernate: create table request (id number(19,0) not null, creation timestamp, modification timestamp, request_data varchar2(32767), request_type varchar2(255 char), service_name varchar2(255), system_name varchar2(255), primary key (id))
[INFO ] 2019-01-03 15:54:28.276 [main] LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[INFO ] 2019-01-03 15:54:28.642 [main] ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
[WARN ] 2019-01-03 15:54:28.670 [main] JpaBaseConfiguration$JpaWebConfiguration$JpaWebMvcConfiguration - 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
[INFO ] 2019-01-03 15:54:28.820 [main] TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''

application startup prints sql queries but none of them are actually executed on database.

2 Answers 2

3

I could solve this issue. I ran the generated sql directly on oracle db and found there was a problem in the column length. I modified the value and build my project and I could see that table got created in the database.

There is one more problem with the spring boot application, the table is getting created during build of the application instead during application start. I will post another question in the forum to get help on this issue + some more issues that I am facing.

Sign up to request clarification or add additional context in comments.

Comments

2

You should pass spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

than your spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

However, I'm not so sure on this about Oracle DBs, it worked for me on Mysql. This shouldn't be dependent on underlying DB, IMO.

For more options on Spring Properties, have look at this link.

4 Comments

As per your suggestion, I changed Dialect property name to spring.jpa.properties.hibernate.dialect and still table is not created.
What is 'test' as last part of your url?? Refer this link, it may help docs.oracle.com/cd/B25329_01/doc/appdev.102/b25320/…
Also, look at Example 3-1 Specifying the Database URL Using a non-XE Client Installation line, in the above url page. Also, see this answer, stackoverflow.com/a/47048336/6446
'test' is a database SID. In the above link, example 3-1 explains about connecting using non-XE client via database service name but not SID. This 'dbc:oracle:thin:@somehost:1521:test' url is correct for connecting to SID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.