Deployment prerequisites

Before running your pipeline(s) and deploying the service project you need to

Attention: Make sure your database schema and tables are already created!

Database connection

You need to provide a connection to the database that will be used by the service project. This can be done either by adding connection properties in you service project's application.yaml

spring.datasource:
  url: "jdbc:db2://<host>:<port>/<database-name>"
  username: <user name>
  password: <password>
  driver-class-name: com.ibm.db2.jcc.DB2Driver

or by adding a configuration class that creates the necessary datasource bean programmatically:

 @Configuration
 public class DataSourceConfig {
    
    @Bean
    public DataSource getDataSource() {
        DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
        dataSourceBuilder.driverClassName("com.ibm.db2.jcc.DB2Driver");
        dataSourceBuilder.url("<database-url>");
        dataSourceBuilder.username("<database-username>");
        dataSourceBuilder.password("<database-password");
        return dataSourceBuilder.build();
    }
}

JPA configuration

  • Add the following JPA configuration to your service project's application.yaml file:

spring.jpa:
  hibernate:
    ddl-auto: node
    show_sql: true
    naming:
      implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
      physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  properties:
    hibernate:
      dialect: org.hibernate.dialect.DB2Dialect

Generating database .ddl files

  • You can generate .ddl scripts for your entities by configuring and using the Maven plugin jpa2ddl included in your service project's pom.xml file

  • You need to provide "SCHEMA_NAME" to be used in the .ddl scripts

  • You can generate .ddl scripts by running the "generate" task of the plugin from within your IDE

  • You need to provide the .ddl scripts to your database administrator and ask for them to be reviewed and your database schema and tables to be created

<plugin>
    <groupId>com.devskiller.jpa2ddl</groupId>
    <artifactId>jpa2ddl-maven-plugin</artifactId>
    <version>0.9.12</version>
    <extensions>false</extensions>
    <!-- required to determine whether to run automatically ot not  -->
    <configuration>
        <outputPath>${basedir}/src/main/resources/database.sql</outputPath>
        <packages>
            <package>de.knowis.kb.demo.kbdemo.sdk.domain</package>
        </packages>
        <jpaProperties>
            <property>
                <name>hibernate.dialect</name>
                <value>org.hibernate.dialect.DB2Dialect</value>
            </property>
            <property>
                <name>hibernate.implicit_naming_strategy</name>
                <value>org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl</value>
            </property>
            <property>
                <name>hibernate.physical_naming_strategy</name>
                <value>org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</value>
            </property>
            <property>
                <name>hibernate.default_schema</name>
                <value>SCHEMA_NAME</value>
            </property>
        </jpaProperties>
        <formatOutput>true</formatOutput>
        <delimiter>;</delimiter>
        <action>CREATE</action>
    </configuration>
</plugin>