Search code examples
springhibernatejpaspring-bootembedded-tomcat-8

How to set Hibernate bulk_id_strategy in spring boot application?


Hibernate is generating temporary tables for TABLE_PER_CLASS inheritance but the prod. oracle user does not have those create table priviledges and therefore that approach is not an option for our project.

Hibernate Version 5.2.8 is said to resolve that issue. We updated our pom.xml accordingly to override default starter hibernate version setting.

Still we dont have any luck with the following property.

 <property name="hibernate.hql.bulk_id_strategy"
 value="org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy"
   />

APPLICATION PROPERTIES is also updated as follows

**

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@192.168.1. :1521:
spring.datasource.username= 
spring.datasource.password= 
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy

**

Where is the proper location of this setting in a spring boot app?

The container is still generating temp tables in the test env. server startup.

kind regards

pom.xml is as follows

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>x.xx.ortakonline</groupId>
<artifactId>PolsanOrtakOnlineServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.0.RELEASE</version>

</parent>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <jjwt.version>0.7.0</jjwt.version>
      <hibernate.version>5.2.8.Final</hibernate.version>
</properties>


<dependencies>
    <dependency>

        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.4.0</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope> test </scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.mobile</groupId>
        <artifactId>spring-mobile-device</artifactId>
    </dependency>


    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
    </dependency>
</dependencies>


Solution

  • In addition all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.

    This comes from the JPA section in the Spring Boot reference guide and, in a nutshell, explains how to pass additional provider specific properties.

    Adding the following to your application.properties should do the trick

    spring.jpa.properties.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy