Using SQL Server 2017 Issues

313 views
Skip to first unread message

JMidkiff

unread,
Nov 24, 2020, 12:37:15 PM11/24/20
to HAPI FHIR
I am trying to get HAPI FHIR connected to my Microsoft SQL Server, SQL Server 2017, using the JPA starter project (5.2.0).

I have added the dependency to the pom file -
<dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.4.1.jre11</version>
</dependency>

and the config to the application.yaml file -
url - jdbc:sqlserver://localhost;databaseName=hapi
dialect - org.hibernate.dialect.SQLServer2012Dialect
driverClassName - com.microsoft.sqlserver.jdbc.SQLServerDriver

And when I start it up it seems to connect fine, but once it gets up and running it throws exceptions.

I started a SQL trace and this is the query it is trying to execute -
exec sp_executesql N'SELECT TOP(@P0) RES_ID FROM ( SELECT t0.RES_ID FROM HFJ_RESOURCE t0 WHERE ((t0.RES_TYPE = @P1) AND (t0.RES_DELETED_AT IS NULL)) )  AS RES_ID',N' @P0 nvarchar(4000),@P1 int',N'SearchParameter',2147483647

This query doesnt return anything (actually errors in sql server when trying to run it from SSMS).  It did create the tables, but I am not sure whats going on here.  I did successfully get this to work (quite smoothly) in an older version of HAPI (5.1.0).  So maybe this is something with this version of HAPI?  I even tried an older version of the SQL Server mssql-jdbc dependency, but it still throws the same errors.

Any help would be great.  Thanks!


Here is the stack trace -
2020-11-24 11:22:57.002 [main] INFO  c.u.f.j.s.BaseSchedulerServiceImpl [BaseSchedulerServiceImpl.java:203] Scheduling local job ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader with interval 00:01:00.000
2020-11-24 11:22:57.025 [main] INFO  org.hibernate.dialect.Dialect [Dialect.java:170] HHH000400: Using dialect: org.hibernate.dialect.SQLServer2012Dialect
2020-11-24 11:22:57.079 [main] WARN  o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:137] SQL Error: 1060, SQLState: S0001
2020-11-24 11:22:57.079 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:142] The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.
2020-11-24 11:22:57.083 [main] ERROR c.u.f.j.s.b.sql.SearchQueryExecutor [SearchQueryExecutor.java:136] Failed to create or execute SQL query
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2304)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2057)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2019)
at org.hibernate.loader.Loader.scroll(Loader.java:2927)
at org.hibernate.loader.custom.CustomLoader.scroll(CustomLoader.java:383)
at org.hibernate.internal.SessionImpl.scrollCustomQuery(SessionImpl.java:2116)
at org.hibernate.internal.AbstractSharedSessionContract.scroll(AbstractSharedSessionContract.java:1168)
at org.hibernate.query.internal.NativeQueryImpl.doScroll(NativeQueryImpl.java:220)
at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:1488)
at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:111)

JMidkiff

unread,
Nov 25, 2020, 1:05:08 PM11/25/20
to HAPI FHIR
Has anyone run into this?  I could really use some help getting this figured out.

Thanks!

Kevin Seegmiller

unread,
Dec 13, 2020, 12:16:03 AM12/13/20
to HAPI FHIR
I am running into the same issue, has anyone been able to use the JPA Server project with SQL Server 2017?

Thanks,

Kevin

Jens Villadsen

unread,
Dec 13, 2020, 6:06:09 AM12/13/20
to HAPI FHIR
This is most likely because the HAPI FHIR starter project now as of 5.2.0 defaults to a native SQL search strategy instead of the generic one using Hibernate. I'll submit a bug referring this discussion, as James should know that there are dialect issues on SQL 2017. The HAPI FHIR starter project should perhaps also have switch to default to the previous strategy (with a performance penalty) making the project functional again

Jens Villadsen

unread,
Dec 13, 2020, 6:10:52 AM12/13/20
to HAPI FHIR

James Agnew

unread,
Dec 13, 2020, 9:25:36 AM12/13/20
to Jens Villadsen, HAPI FHIR
Hi Kevin,

Are you able to try this again on the current HAPI FHIR 5.3.0-SNAPSHOT builds? I believe this issue is solved in current master.

You can try out this branch by checking out this PR: https://github.com/hapifhir/hapi-fhir-jpaserver-starter/pull/190

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/f3acbb18-2789-4f30-a45d-ac490cbb8052n%40googlegroups.com.

Kevin Seegmiller

unread,
Dec 14, 2020, 8:48:21 PM12/14/20
to HAPI FHIR
Hi James,

I used the 5.3.0-SNAPSHOT with the rel_5.3.0 branch and I get the same error.  

2020-12-14 18:44:37.004 [main] WARN  o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:137] SQL Error: 1060, SQLState: S0001
2020-12-14 18:44:37.005 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:142] The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.
2020-12-14 18:44:37.009 [main] ERROR c.u.f.j.s.b.sql.SearchQueryExecutor [SearchQueryExecutor.java:136] Failed to create or execute SQL query
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:67)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:2304)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2057)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2019)
        at org.hibernate.loader.Loader.scroll(Loader.java:2927)
        at org.hibernate.loader.custom.CustomLoader.scroll(CustomLoader.java:383)
        at org.hibernate.internal.SessionImpl.scrollCustomQuery(SessionImpl.java:2116)
        at org.hibernate.internal.AbstractSharedSessionContract.scroll(AbstractSharedSessionContract.java:1168)
        at org.hibernate.query.internal.NativeQueryImpl.doScroll(NativeQueryImpl.java:220)
        at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:1488)
        at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:111)
        at ca.uhn.fhir.jpa.search.builder.sql.SearchQueryExecutor.fetchNext(SearchQueryExecutor.java:122)
        at ca.uhn.fhir.jpa.search.builder.sql.SearchQueryExecutor.hasNext(SearchQueryExecutor.java:87)
        at ca.uhn.fhir.jpa.search.builder.SearchBuilder$QueryIterator.fetchNext(SearchBuilder.java:1076)
        at ca.uhn.fhir.jpa.search.builder.SearchBuilder$QueryIterator.hasNext(SearchBuilder.java:1207)
        at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.lambda$searchForIds$10(BaseHapiFhirResourceDao.java:1334)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
        at ca.uhn.fhir.jpa.dao.tx.HapiTransactionService.execute(HapiTransactionService.java:65)
        at ca.uhn.fhir.jpa.dao.tx.HapiTransactionService.execute(HapiTransactionService.java:56)
        at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.searchForIds(BaseHapiFhirResourceDao.java:1322)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy240.searchForIds(Unknown Source)
        at ca.uhn.fhir.jpa.cache.ResourceVersionSvcDaoImpl.getVersionMap(ResourceVersionSvcDaoImpl.java:55)
        at ca.uhn.fhir.jpa.cache.ResourceChangeListenerCacheRefresherImpl.refreshCacheAndNotifyListener(ResourceChangeListenerCacheRefresherImpl.java:118)
        at ca.uhn.fhir.jpa.cache.ResourceChangeListenerCache.lambda$refreshCacheAndNotifyListenersWithRetry$0(ResourceChangeListenerCache.java:140)
        at ca.uhn.fhir.jpa.searchparam.retry.Retrier.lambda$runWithRetry$0(Retrier.java:87)
        at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:287)
        at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:164)
        at ca.uhn.fhir.jpa.searchparam.retry.Retrier.runWithRetry(Retrier.java:87)
        at ca.uhn.fhir.jpa.cache.ResourceChangeListenerCache.refreshCacheAndNotifyListenersWithRetry(ResourceChangeListenerCache.java:143)
        at ca.uhn.fhir.jpa.cache.ResourceChangeListenerCache.refreshCacheWithRetry(ResourceChangeListenerCache.java:130)
        at ca.uhn.fhir.jpa.cache.ResourceChangeListenerCache.forceRefresh(ResourceChangeListenerCache.java:85)
        at ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl.requiresActiveSearchParams(SearchParamRegistryImpl.java:104)
        at ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl.getActiveSearchParam(SearchParamRegistryImpl.java:86)
        at ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader.getSearchParameterMap(SubscriptionLoader.java:167)
        at ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader.registerListener(SubscriptionLoader.java:88)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:429)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1780)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at ca.uhn.fhir.jpa.starter.Application.main(Application.java:33)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
        at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1624)
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:594)
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:524)
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2979)
        at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
        at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:446)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
        ... 78 common frames omitted



This is some of the configuration in the application.yaml

spring:
  datasource:
    url: 'jdbc:sqlserver://localhost:1433;DatabaseName=test_db;sendStringParametersAsUnicode=false'
    username: test_db
    password: test_db
    driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
    max-active: 15
  jpa:
    properties:
      hibernate.dialect: org.hibernate.dialect.SQLServer2012Dialect
      hibernate.search.model_mapping: ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory
      hibernate.format_sql: true
      hibernate.show_sql: true
      hibernate.use_sql_comments: true
      hibernate.hbm2ddl.auto: update
      hibernate.jdbc.batch_size: 20
      hibernate.jdbc.fetch_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

Kevin Dougan

unread,
Dec 15, 2020, 8:09:50 AM12/15/20
to HAPI FHIR
I see that you turned on SQL display with these properties:
      hibernate.format_sql: true
      hibernate.show_sql: true

Can you check the log just above that Error message and see if it also printed out the exact SQL it was trying to execute?
That would be helpful in determining what's wrong with the Query.

Kevin Seegmiller

unread,
Dec 15, 2020, 6:05:36 PM12/15/20
to HAPI FHIR
This is the SQL.

2020-12-14 18:44:37.558 [main] ERROR c.u.f.jpa.searchparam.retry.Retrier [Retrier.java:79] Retry failure 2/60: ca.uhn.fhir.rest.server.exceptions.InternalErrorException: could not extract ResultSet
Hibernate:
    /* dynamic native SQL query */ SELECT
        TOP(?) t0.RES_ID
    FROM
        HFJ_RESOURCE t0
    WHERE
        (
            (
                t0.RES_TYPE = ?
            )
            AND (
                t0.RES_DELETED_AT IS NULL
            )
        )
2020-12-14 18:44:38.571 [main] WARN  o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:137] SQL Error: 1060, SQLState: S0001
2020-12-14 18:44:38.573 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:142] The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.

Kevin Seegmiller

unread,
Dec 21, 2020, 12:34:36 PM12/21/20
to HAPI FHIR
Any luck on determining a fix for this issue?

Thanks,

Kevin

James Agnew

unread,
Jan 1, 2021, 7:20:29 PM1/1/21
to Kevin Seegmiller, HAPI FHIR
This has now been addressed in this fix: https://github.com/hapifhir/hapi-fhir/pull/2265

I'll push a new 5.3.0-SNAPSHOT build as soon as the fix gets merged, should be inthe next 24 hours.

Cheers,
James

Reply all
Reply to author
Forward
0 new messages