amazon-web-services - 通过 JPA spring boot 访问 AWS athena

标签 amazon-web-services jpa spring-boot amazon-athena

我正在尝试使用 spring boot jpa 数据源使用 AWS athena。
我尝试使用给定的属性设置数据源。

    spring.datasource.driver-class-name=com.amazonaws.athena.jdbc.AthenaDriver
    spring.datasource.url=jdbc:awsathena://athena.us-east-1.amazonaws.com:443/default
    spring.datasource.username=*****
    spring.datasource.password=***
    spring.datasource.tomcat.connectionProperties=s3_staging_dir=*****

我低于异常
    Caused by:org.springframework.beans.BeanInstantiationException:    Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(Constructo`enter code here`rResolver.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 51 common frames omitted
    Caused by: java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.jdbc.DatabaseDriver.fromJdbcUrl(DatabaseDriver.java:268) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624.CGLIB$jpaVendorAdapter$4(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624$$FastClassBySpringCGLIB$$9766cf.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 

最佳答案

默认情况下,Spring boot 会自动检测哪个 Hibernate Dialect基于从 JDBC 驱动程序检索到的 Datasource 的元数据来使用。

此错误是由于 Athena JDBC 驱动程序无法获取相关元数据。不确定为什么会失败,但您可以绕过此检测并通过声明 JpaVendorAdapter 来明确声明自己要使用哪种 Hibernate 方言| bean 角,扁 bean :

@Bean
public JpaVendorAdapter jpaVendorAdapter(JpaProperties properties) {
    AbstractJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(properties.isShowSql());
    adapter.setGenerateDdl(properties.isGenerateDdl());
    return adapter;
}

我保留所有默认行为,但只是禁用自动检测方言

并在 application.properties 中定义方言:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.XXXXXX

但关键是我怀疑 Athena 是否可以与 Hibernate 一起使用,因为我找不到 Athena 的现有方言。所以我的建议是:
  • 试试另一个数据库中的方言,它的 SQL 语法类似于 Athena。它不适用于 some cases. 也就不足为奇了。
  • 自己实现雅典娜方言。
  • 关于amazon-web-services - 通过 JPA spring boot 访问 AWS athena,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089385/

    相关文章:

    java - Spring boot ModelAndView值不显示

    java - 如何将hibernate注解应用到抽象类的子类上

    mysql - Mongo Restore 在 AWS 上的分片集群环境中显示无可访问服务器错误?

    amazon-web-services - 执行 API 网关的 AWS CLI 命令

    amazon-web-services - 公共(public)存储库中的 AWS 域证书 ARN

    database - JPA 缓存与数据库的并发访问保持同步

    java - 使用orientdb注解自动填充Pojo

    java - 在 persistence.xml 中引用 Tomcat JNDI 数据源

    amazon-web-services - Amazon AWS Athena HIVE_CANNOT_OPEN_SPLIT : Error opening Hive split/Not valid Parquet file, parquet 文件使用 Athena 压缩为 gzip

    java - 当应用程序部署在cloudfoundry上时,spring-boot web应用程序的ContextClosedEvent未完成