Hive/SparkSQL 的 Hibernate 方言? [英] Hibernate dialect for Hive/SparkSQL?
问题描述
我有一个用于连接到 MySQL
的应用程序,并且我有 Hibernate
配置像这样:
I have an app that used to connect to MySQL
, and I have Hibernate
config
for it like this:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://somehost:3306/some_db</property>
...
现在如果我想连接到 Hive/SparkSQL
,这些属性的等效值是什么?
Now if I want to connect to Hive/SparkSQL
instead, what would the
equivalent values for these properties be?
我对 driver_class
和 url
有一些想法(假设我们使用端口 10000
),但是 dialect
是?
I have some ideas on driver_class
and url
(assuming we are using port 10000
), but what should the dialect
be?
<property name="hibernate.connection.driver_class">org.apache.hive.jdbc.HiveDriver</property>
<property name="hibernate.connection.url">jdbc:hive2://someHost:10000</property>
更新
我尝试了许多不同的值,但没有一个有效.(我还没有找出 Apache Hive 安装使用的元存储,所以在这里我只是在反复试验)
I tried many different values but none of them work. (I have yet to find out what metastore the Apache Hive installation uses, so here I was just doing trial-and-error)
org.hibernate.dialect.MySQLDialect
org.hibernate.dialect.MySQLInnoDBDialect
org.hibernate.dialect.DerbyDialect
org.hibernate.dialect.DerbyTenFiveDialect
org.hibernate.dialect.Oracle10gDialect
org.hibernate.dialect.H2Dialect
org.hibernate.dialect.Dialect
我注意到在所有情况下,都有来自休眠说:
I noticed that in all case, there is a warning from Hibernate that said:
WARN JdbcServicesImpl,main:160 - \
HHH000341: Could not obtain connection metadata : \
Method not supported
然后代码会遇到NullPointerException
在 org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure()
(4.2.0.Final 中的第 207 行).
And then the code would run into a NullPointerException
in org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure()
(Line 207 in 4.2.0.Final).
我下载了Hibernate的源代码,并跟踪了逻辑.异常是由于变量前面几行引起的dialect
(Dialect
类型)被确定为 null
由于尝试执行第 138 行时捕获的异常:
I downloaded the source code of Hibernate and traced the logic.
The exception was caused because a few line ahead a variable
dialect
(of type Dialect
) was determined to be null
due to
an exception caught when trying to execute Line 138:
metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
例外是
java.sql.SQLException: Method not supported
(导致上面的警告信息)
(that caused the above warning message)
这是否意味着我不能将 Hibernate
与 Apache Hive 一起使用?如果是这样,那就这样吧.(我想我会有换掉这部分的 Hibernate
实现)但是我很想知道权威的答案
Does that mean I cannot use Hibernate
with Apache Hive?
If that is the case, then so be it. (I guess I would have
to swap out the Hibernate
implementation for this part)
But I am curious to know the authoritative answer
on this.
在互联网上我找不到有力的证据表明人们已经成功地将 Hibernate
与 Apache Hive 结合使用.
On the Internet I could not find strong evidence that
people have been using Hibernate
successfully with Apache Hive.
推荐答案
我在这里回答我自己的问题.
I am answering my own question here.
我认为 Hibernate 的答案是不——Hive/SparkSQL 没有方言".显然,Hibernate 中不支持 HiveServer2(即不是 Hive Metastore).我相信截至目前(2017-10-19)这是真的(95% 的置信度).
I think the answer is "No -- there is no dialect for Hive/SparkSQL" for Hibernate. Apparently there are no support for HiveServer2 (i.e. not the Hive Metastore) in Hibernate. I believe this is true (95% confidence) as of now (2017-10-19).
就我而言,我最终重写了我的代码并将 Hibernate 代码替换为直接 JDBC 代码.我很幸运,那里的 Hibernate 代码只是用于简单的 DB 查询(session.createSQLQuery()
)而不是严重的 ORM,因此更改相对容易.
In my case, I ended up rewriting my code and replacing the Hibernate code to direct JDBC code instead. I was lucky that the Hibernate code there was just for simple DB query (session.createSQLQuery()
) not serious ORM, so the change was relatively easy.
这篇关于Hive/SparkSQL 的 Hibernate 方言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!