Using Postgres: 'Unable to detect database type'.

3,382 views
Skip to first unread message

Brian Forester

unread,
Jul 25, 2022, 1:37:29 PM7/25/22
to HAPI FHIR
I'm just starting my journey on working with the HAPI FHIR JPA starter.
The out of the box configuration with H2 worked just fine.

My next step was to point to a postgres installation ( Docker) and I've started getting this error.
```
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.batch.BatchDataSourceScriptDatabaseInitializer]: Factory method 'batchDataSourceInitializer' threw exception; nested exception is java.lang.IllegalStateException: Unable to detect database type
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 163 common frames omitted
Caused by: java.lang.IllegalStateException: Unable to detect database type
    at org.springframework.util.Assert.state(Assert.java:76)
```

My configuration changes to the application.yaml file:  https://gist.github.com/BDF/0d4d0c068b10ff96300c3dd63e34784d

I've come across a description of a very similar error for sysbase here:  https://github.com/spring-projects/spring-boot/issues/28897

Before I spend too much more time on this I wanted to see if anyone had a similar issue.   I see couple of paths to explore from here.   I can try some of the solutions mentioned in the above link.    I could try bumping the Spring Boot to version '2.7'.

Thank you ahead of time for any suggestions,
Brian F.

p.s.
I'm using OpenJDK 17.0.2; so if other investigations fail I can try falling back to other versions of Java if other options fail.


Brian Forester

unread,
Jul 25, 2022, 1:58:17 PM7/25/22
to HAPI FHIR

So, looking more closely at the configuration file I see this:

      #Hibernate dialect is automatically detected except Postgres and H2.
      #If using H2, then supply the value of ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect
      #If using postgres, then supply the value of ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect

That looks very promising so I'm going to try that next.

alejandro...@gmail.com

unread,
Jul 25, 2022, 3:19:32 PM7/25/22
to Brian Forester, HAPI FHIR
Hi, Brian:

that its correct, you need to add to your properties file the dialect for hibernate, for postgres it's something like this:

https://github.com/hapifhir/hapi-fhir-jpaserver-starter/blob/5c102f76fc133846ee9a1154e94ca60a453a2442/src/main/resources/application.yaml#L35

jpa:
   properties:
      hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect

Best regards.

--
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/2fd86f2f-5816-4694-bb53-02f95e41fc00n%40googlegroups.com.


--
______________________________
Alejandro Sebastián Medina Negrete
Ingeniero Civil en Computación

Brian

unread,
Jul 25, 2022, 4:10:18 PM7/25/22
to HAPI FHIR
Thanks for the reply Alejandro,

I did make that change but I'm still getting the same error.  I've updated the gist with the full application.yaml that I'm using .
Just the two changes.   The  hibernate dialect change
hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect
change and the datasource change.
datasource:
url: 'jdbc:postgresql://localhost:5432/hapi_dstu3'
username: postgres
password: 'password'
driverClassName: org.postgresql.Driver
I will reply with updates as I try out different paths.

Brian F.



alejandro...@gmail.com

unread,
Jul 25, 2022, 9:10:05 PM7/25/22
to Brian, HAPI FHIR
Brian:

Can you share the folder structure of your project, the version of the hapi-fhir-jpaserver-starter and the path of your application.yaml please?

Thanks.


Brian Forester

unread,
Jul 26, 2022, 12:51:27 PM7/26/22
to HAPI FHIR
This is  an 'out of the box' fork of the https://github.com/hapifhir/hapi-fhir project.

The only differences from the base project are the ones discussed:

I've tried a couple of the suggestions in the read me including building the docker ( same error) and running the mvn command: 
mvn clean spring-boot:run -Pboot

I've not dug into the code yet, but when I do I will report back.

Brian F.

alejandro...@gmail.com

unread,
Jul 26, 2022, 1:36:59 PM7/26/22
to Brian Forester, HAPI FHIR
Brian, maybe you need to check your maven versión(I use 3.8.6) and jdk version(I use jkd17)

I tested this project with a postgresql database configuration and it's working fine.



Brian Forester

unread,
Jul 26, 2022, 2:30:11 PM7/26/22
to HAPI FHIR
Hi Alejandro,

Do you have a git repo out there I can take a look at?    I'm not convinced we are looking at the same code base.

When I downgrade to Amazon Corretto Java 1.8 I get this error:
> mvn clean spring-boot:run -Pboot
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
HAPI FHIR is targeting JDK 11 for published binaries, but we require JDK 17 to build and test this library.
Caused by: org.apache.maven.plugin.MojoExecutionException: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed.


thank you for testing,
Brian F.

alejandro...@gmail.com

unread,
Jul 26, 2022, 3:08:59 PM7/26/22
to Brian Forester, HAPI FHIR
Hi, I am using this project https://github.com/BDF/hapi-fhir-jpaserver-starter and only changing the database config in application.yaml with this:
datasource:
url: 'jdbc:postgresql://localhost:5432/hapi'
#url: jdbc:h2:mem:test_mem
username: postgres
password: postgres
driverClassName: org.postgresql.Driver
max-active: 15
jpa:
properties:
hibernate.format_sql: false
hibernate.show_sql: false

#Hibernate dialect is automatically detected except Postgres and H2.
#If using H2, then supply the value of ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect
#If using postgres, then supply the value of ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect

    hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect

I have to update to jdk17 to start the server

Brian Forester

unread,
Jul 26, 2022, 4:25:49 PM7/26/22
to HAPI FHIR
Good news, I am past the database error.

I was expecting the same behavior that the H2 configuration gave; namely that the database would be created as part of the startup process.
That did not work, I needed to create database first.  (i.e. hapi_dstu3)   Then the code properly connects an existing database.

Sorry for the churn, and thanks for your help Alejandro.
People's time and attention is always appreciated.

I do have a different error now, but I will spend sometime with that one before posting any new questions.

Brian F.
Reply all
Reply to author
Forward
0 new messages