Is there any tutorial on how to change database?

878 views
Skip to first unread message

live.i...@gmail.com

unread,
Jul 24, 2018, 2:27:38 PM7/24/18
to HAPI FHIR
I just downloaded the Jpa database server 3.4.0. I realized it is using Derby to store data. I wish to switch to MySQL. But I didn't find any documents about the structure of the database(like column name). Also, I have no idea about how to modify the Java code to use MySQL. I found a lot of people were using MySQL. Please help me!!

Thank you very much

Jean-Karlo Accetta

unread,
Jul 24, 2018, 3:28:00 PM7/24/18
to HAPI FHIR
I'd recommend taking a look at the sample files; I know one of them has a Postgres backend.

Essentially, you need is to remove the Derby dependenciesand add the MySQL dependencies in the pom file, then change how the app connects to the DataSource. This can be done in various ways:
  1. Define beans to achieve this in some class tagged with @Configuration (or directly in the class tagged with @SpringBootApplication)
    1. Example file: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java
  2. Define/update the application.yml or application.properties file to connect to the appropriate database using the appropriate hibernate.dialect
    1. Example file: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/main/resources/application.yml
    2. In this example, you would have to remove the "h2" property and add the appropriate MySQL properties -- in my example, I use the below application.yml:

spring:
 jpa
:
 show
-sql: false
 hibernate
:
 ddl
-auto: update
 
use-new-id-generator-mappings: true
 properties
:
 hibernate
.dialect: org.hibernate.dialect.PostgreSQL95Dialect
 hibernate
.format-sql: true
 hibernate
.show-sql: false
 hibernate
.temp.use_jdbc_metadata_defaults: false
 hibernate
.jdbc.batch_size: 20
 hibernate
.cache.use_query_cache: false
 hibernate
.cache.use_second_level_cache: false
 hibernate
.cache.use_structured_entries: false
 hibernate
.cache.use_minimal_puts: false
 hibernate
.search.default.directory_provider: filesystem
 hibernate
.search.default.indexBase: target/lucenefiles
 hibernate
.search.lucene_version: LUCENE_CURRENT
 hibernate
.search.model_mapping: ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory
 generate
-ddl: true
 database
-platform: org.hibernate.dialect.PostgreSQL95Dialect
 database
: postgresql
 datasource
:
 platform
: postgres
 driver
-class-name: org.postgresql.Driver
 url
: jdbc:postgresql://localhost:5432/db-name
 username
: db-user
 password
: db-pwd

Kevin Mayfield

unread,
Jul 24, 2018, 3:42:55 PM7/24/18
to Jean-Karlo Accetta, HAPI FHIR
In addition to Jean-Karlo’s reply.

HAPI (or more accuratley JPA/HIbernate) will generate your tables. You will need to create and configure the database itself.




--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/33642963-4b85-4be6-bf54-e725935b3b55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

live.i...@gmail.com

unread,
Jul 24, 2018, 10:03:56 PM7/24/18
to HAPI FHIR
Thank you very much

live.i...@gmail.com

unread,
Jul 24, 2018, 10:06:10 PM7/24/18
to HAPI FHIR
Thank you very much
Reply all
Reply to author
Forward
0 new messages