问题描述
我有一个应用程序用于连接 MySQL
,并且我有 Hibernate
config
它就像这样:
< 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
相反,这些属性的
等价值是什么?
我对 driver_class 和 url
(假设我们使用port 10000
),但是 dialect
be?
< property name =hibernate.connection。 driver_class> org.apache.hive.jdbc.HiveDriver< /性>
< property name =hibernate.connection.url> jdbc:hive2:// someHost:10000< / property>
更新
来找出Apache Hive安装使用的是什么metastore,所以这里
我只是做了试错)
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
我注意到,在所有情况下,从
Hibernate有一个警告说:
WARN JdbcServicesImpl,main:160 - \
HHH000341:无法获取连接元数据:\
不支持的方法
然后代码会在中运行到
NullPointerException
中, org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure()
(4.2.0.Final中的207行)。
异常是由于变量
dialect
(类型 Dialect
)被确定为 null
,因为是尝试执行第138行时捕获的异常:
metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
例外是
java.sql.SQLException:不支持的方法
(导致上述警告消息)
这是否意味着我不能在Apache Hive中使用 Hibernate
?
如果是这样,那就这样吧。 (我想我会有
换出这部分的 Hibernate
实现)
但是我很想知道权威答案
在互联网上,我找不到有力的证据证明
的人一直在使用 Hibernate
成功使用Apache Hive。
我认为Hibernate的答案是不 - Hive / SparkSQL没有方言。显然在Hibernate中不支持HiveServer2(即不是Hive Metastore)。我相信这是真实的(95%的置信度)截至目前(2017-10-19)。
在我的情况下,我最终重写了我的代码并替换了Hibernate代码来指导JDBC代码。幸运的是,那里的Hibernate代码只是用于简单的数据库查询( session.createSQLQuery()
)不是严重的ORM,因此这种更改相对容易。
I have an app that used to connect to MySQL
, and I have Hibernate
configfor 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>
...
Now if I want to connect to Hive/SparkSQL
instead, what would theequivalent values for these properties be?
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>
Update
I tried many different values but none of them work. (I have yetto find out what metastore the Apache Hive installation uses, so hereI 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 fromHibernate that said:
WARN JdbcServicesImpl,main:160 - \
HHH000341: Could not obtain connection metadata : \
Method not supported
And then the code would run into a NullPointerException
in org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure()
(Line 207 in 4.2.0.Final).
I downloaded the source code of Hibernate and traced the logic.The exception was caused because a few line ahead a variabledialect
(of type Dialect
) was determined to be null
due toan exception caught when trying to execute Line 138:
metaReportsDDLCausesTxnCommit = meta.dataDefinitionCausesTransactionCommit();
The exception was
java.sql.SQLException: Method not supported
(that caused the above warning message)
Does that mean I cannot use Hibernate
with Apache Hive?If that is the case, then so be it. (I guess I would haveto swap out the Hibernate
implementation for this part)But I am curious to know the authoritative answeron this.
On the Internet I could not find strong evidence thatpeople have been using Hibernate
successfully with Apache Hive.
I am answering my own question here.
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).
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方言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!