hbase 用HTablePool 类获取hbaseTable报错
Exception in thread "main" java.lang.ClassCastException: org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apache.hadoop.hbase.client.HTable
at com.tdpress.hbase.test.JinTaoTest.insertData(JinTaoTest.java:87)
at com.tdpress.hbase.test.JinTaoTest.main(JinTaoTest.java:41)
at com.tdpress.hbase.test.JinTaoTest.insertData(JinTaoTest.java:87)
at com.tdpress.hbase.test.JinTaoTest.main(JinTaoTest.java:41)
HTable table = new HTable(configuration,tabName);
这样是可能正常创建table对象
错误 :
2/12/12 16:33:32 INFO zookeeper .RecoverableZooKeeper: The identifier of this process is 3260@xuping-c2b2bf6c
Exception in thread "main" java.lang.ClassCastException: org.apache.hadoop.hbase. client .HTablePool$PooledHTable cannot be cast to org.apache.hadoop.hbase.client.HTable
at com.util.HbaseTest.main(HbaseTest.java:30)
这样是可能正常创建table对象
错误 :
2/12/12 16:33:32 INFO zookeeper .RecoverableZooKeeper: The identifier of this process is 3260@xuping-c2b2bf6c
Exception in thread "main" java.lang.ClassCastException: org.apache.hadoop.hbase. client .HTablePool$PooledHTable cannot be cast to org.apache.hadoop.hbase.client.HTable
at com.util.HbaseTest.main(HbaseTest.java:30)
问题解决 : HTablePool pool = new HTablePool(configuration, 1000); HTable table = (HTable) pool.getTable("tmp_tb"); 其中pool.getTable返回的不是HTable而是HTableInterface 类,直接使用后者提供的put方法即可插入数据(网上的代码返回类型不一致估计是版本的原因) |