How to configure HAPI-FHIR with MySQL?

2,657 views
Skip to first unread message

Avu

unread,
Mar 7, 2017, 3:41:04 AM3/7/17
to HAPI FHIR
Hello all,

I have set up the HAPI FHIR using Command line tools. Its working now. But I have to connect it with MySQL?

Guide me the required steps to be done. Thanks in advance

James Agnew

unread,
Mar 7, 2017, 10:36:31 AM3/7/17
to Avu, HAPI FHIR
Hi Avu,

Unfortunately the CLI tool does not currently support databases other than Derby.

If you want to support MySQL you'll need to create a WAR project and configure it for MySQL. The hapi-fhir-jpaserver-example project can be a good starting point, but you'll have to switch the dialect and datasource properties to reflect MySQL.

Cheers,
James

--
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+unsubscribe@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/9bd909df-14e6-4668-928a-ceb7cbcd7cdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Avu

unread,
Mar 8, 2017, 1:33:35 PM3/8/17
to HAPI FHIR
HI James,
I have gone through hapi-fhir-jpaserver-example from the link   "https://github.com/jamesagnew/hapi-fhir"

Then I imported it into eclipse as maven project and edited  FhirServerConfig.java  to configure with mysql. also I added maven dependency for tomcat server.
I used mvn install command,given me a war file under target folder.Finally i placed it in webapps directory.

http://localhost:8060/hapi-fhir-jpaserver-example/fhir/

gives me 404 error..

Were all my followed steps right??

Kevin Mayfield

unread,
Mar 8, 2017, 2:30:48 PM3/8/17
to Avu, HAPI FHIR
--
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.

Avu

unread,
Mar 9, 2017, 3:46:56 AM3/9/17
to HAPI FHIR

Hi James/Kevin,

Please find the image and  I am bit confused about where the database connection has made??

Could you please explain it?


On Tuesday, March 7, 2017 at 2:11:04 PM UTC+5:30, Avu wrote:

Kevin Mayfield

unread,
Mar 9, 2017, 3:57:58 AM3/9/17
to Avu, HAPI FHIR
In your FhirServerConfig file, what do you have for the DataSource Bean?

You should have something that looks like 

 Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName("com.mysql.jdbc.Driver");

In addition in the jpaProperties you should have a line like:

extraProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");



--
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+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.
Message has been deleted

marcelocabe...@gmail.com

unread,
Oct 17, 2017, 8:46:09 AM10/17/17
to HAPI FHIR
Hi all,
In my case I made a configuration to run JPA_Server with MySql. The engine required to adjust the same TimeZone inside MySql and the JDBC connector. Otherwise, Maven shows compilation errors.

This are the steps that I made:

1. Let's assume I created this database. By default I created an INNODB type

CREATE DATABASE dbhapi DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

CREATE USER 'fhirman' IDENTIFIED BY '******';

GRANT ALL ON dbhapi TO fhirman;

FLUSH PRIVILEGES;



2. In my.ini add this line and restart MySql:
default-time-zone = '+00:00'


3. Add the dependency in POM.XML

<dependency>

        <groupId>mysql</groupId>

        <artifactId>mysql-connector-java</artifactId>

        <version>6.0.5</version>

</dependency>

<!--


4. In FhirServerConfig.java
4a. Make sure you add this line:

import java.sql.*;



4b. Then modify the datasource()

public DataSource dataSource() {

   BasicDataSource retVal = new BasicDataSource();

      try {

            retVal.setDriver(new com.mysql.cj.jdbc.Driver());

          } catch (SQLException e) {

         // TODO Auto-generated catch block

            e.printStackTrace();

           }

retVal.setUrl("jdbc:mysql://localhost:3306/dbfhir?useSSL=false&serverTimezone=UTC");

 

         retVal.setUsername("fhirman");

         retVal.setPassword("******");

         return retVal;

        }


4c. On the jpaProperties, modify the line:

private Properties jpaProperties() {

  Properties extraProperties = new Properties();

  extraProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");

  extraProperties.put("hibernate.format_sql", "true");

  extraProperties.put("hibernate.show_sql", "false");

  extraProperties.put("hibernate.hbm2ddl.auto", "update");

  extraProperties.put("hibernate.jdbc.batch_size", "20");

  extraProperties.put("hibernate.cache.use_query_cache", "false");

  extraProperties.put("hibernate.cache.use_second_level_cache", "false");

  extraProperties.put("hibernate.cache.use_structured_entries", "false");

  extraProperties.put("hibernate.cache.use_minimal_puts", "false");

  extraProperties.put("hibernate.search.default.directory_provider", "filesystem");

  extraProperties.put("hibernate.search.default.indexBase", "target/lucenefiles");

  extraProperties.put("hibernate.search.lucene_version", "LUCENE_CURRENT");

  //extraProperties.put("hibernate.search.default.worker.execution", "async");

return extraProperties;


Cheers,
Marcelo

trantro...@gmail.com

unread,
Oct 14, 2018, 5:23:13 AM10/14/18
to HAPI FHIR
Hi Marcelo. Correct me if I'm wrong. You created Database and did not create any table right? And after modifying the project, you use cmd mvn install again to make a new *.war, right?
Message has been deleted

Marcelo Cabello

unread,
Dec 6, 2019, 8:45:30 AM12/6/19
to HAPI FHIR
From version JPA-STARTER is much easier to configure the database:

datasource.driver=com.mysql.cj.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/<database name>?useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
datasource.username=<user>
datasource.password=<password>

Cheers!
Marcelo

Octavian Ianculescu

unread,
May 26, 2021, 8:01:46 AM5/26/21
to HAPI FHIR
Just FYI that besides the setup above within the JPA-STARTER project, on UNIX file-systems it also looks mysql schema needs to be case-insensitive in order for Hibernate to properly work and create the FHIR schema in mysql.
See https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html

Setting lower_case_table_names=1 for a fresh mysql 5.7 docker container did the trick for me.

James Agnew

unread,
May 26, 2021, 8:37:47 AM5/26/21
to Octavian Ianculescu, HAPI FHIR
Hi Octavian,

Thanks for the sharing! Any chance you could submit a PR against the README to add these instructions?

Cheers,
James

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/644b5881-ed70-4ab8-9f54-31f2179bf7b2n%40googlegroups.com.

Tomomi Yamano

unread,
Feb 4, 2022, 2:18:45 AM2/4/22
to HAPI FHIR
Hi,

Thank you for your share. 
I am also working on this, though. Has this instruction been added in Readme?

Best, 


Reply all
Reply to author
Forward
0 new messages