日期:2014-05-16  浏览次数:20448 次

Hive源码分析(三) hadoop.hive.metastore.model.MDatabase is not persistable异常解决

? 本博客属原创文章,转载请注明出处:http://guoyunsky.iteye.com/blog/1178076 ??

? ?欢迎加入Hadoop超级群:?180941958

?

当我在Eclipse中跑起Hive,运行show tables命令后,发现报这个异常:

> hive> show tables;
> show tables;
> FAILED: Error in metadata:
> org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The
> class "org.apache.hadoop.hive.metastore.model.MDatabase" is not persistable.
> This means that it either hasnt been enhanced, or that the enhanced version
> of the file is not in the CLASSPATH (or is hidden by an unenhanced version),
> or the Meta-Data/annotations for the class are not found.
> NestedThrowables:

> org.datanucleus.exceptions.ClassNotPersistableException: The class
> "org.apache.hadoop.hive.metastore.model.MDatabase" is not persistable. This
> means that it either hasnt been enhanced, or that the enhanced version of
> the file is not in the CLASSPATH (or is hidden by an unenhanced version), or
> the Meta-Data/annotations for the class are not found.
> FAILED: Execution Error, return code 1 from
> org.apache.hadoop.hive.ql.exec.DDLTask
> hive>
>

?

跟踪源码发现加上知道Hive是利用其他数据库,如默认到derby,mysql等保存表和数据库信息。而这块代码在获取数据库时所触发,代码如下:

private MDatabase getMDatabase(String name) throws NoSuchObjectException {
    MDatabase mdb = null;
    boolean commited = false;
    try {
      openTransaction();
      name = name.toLowerCase().trim();
      Query query = pm.newQuery(MDatabase.class, "name == dbname");
      query.declareParameters("java.lang.String dbname");
      query.setUnique(true);
      mdb = (MDatabase) query.execute(name);
      pm.retrieve(mdb);
      commited = commitTransaction();
    } finally {
      if (!commited) {
        rollbackTransaction();
      }
    }
    if (mdb == null) {
      throw new NoSuchObjectException("There is no database named " + name);
    }
    return mdb;
  }

?? 所触发异常是在 mdb = (MDatabase) query.execute(name);这行,也就是要去derby或mysql等(根据你到hive-default.xml配置)获取数据库到时候所触发。三思不得其解,跟进代码发现跟javax.jdo有关系。以前没接触过,于是google了下。按照这个说明搞定这个错误:http://www.datanucleus.org/products/accessplatform/guides/eclipse/index.html

???? 我大概说下过程,原理日后再研究:

??? 1)通过Eclipse安装datanucleus

??????? Help->Install New Software->Work with输入框里输入网址http://www.datanucleus.org/downloads/eclipse-update/

??? 2)设置datanucleus

?????? Window->Preferences->DataNucleus->SchemaTool->

?????? 根据你在hive-default.xml里的配置进行设置Drive Path、Driver Name、Connection URL:

?????? 比如我这里采用默认到derby嵌入式数据库,设置如下:

?????? Drive Path:file:/home/hadoop/workspace/hive-0.7.0/lib/derby.jar (derby.jar到路径)

?????? Driver Name:org.apache.derby.jdbc.EmbeddedDriver

????? Connection URL:jdbc:derby:/path/db-name;[create=true]

?? 3)在你到工程上部署datanucleus,也就是hive源码:

????? 右击Hive源码工程->DataNucleus->Add DataNucleus Support->

????? 之后再看Hive源码工程的Dataucleus会多几项,我依次点击运行了Enable Auto-Enhancement,Run Enhancer Tool,Run Schema Tool

?

?之后再跑Hive源码,运行SHOW TABLES.OK!一切正常

?