2016-05-24 44 views
0

我有一個ComposedIdKey類,用於爲Customer類創建組合鍵。 我可以用複合鍵成功在Hbase中插入這個對象。 然而,當我嘗試訪問該對象得到以下信息:DataNucleus + JDO:使用複合鍵檢索對象(錯誤:NoSuchElementException)

java.util.NoSuchElementException 
     at java.util.StringTokenizer.nextToken(StringTokenizer.java:349) 
     at DN_Schema.ComposedIdKey.<init>(ComposedIdKey.java:26) 
     at DN_Schema.Customer_JDO3.dnNewObjectIdInstance(Customer_JDO3.java) 
     at org.datanucleus.enhancer.EnhancementHelper.newObjectIdInstance(EnhancementHelper.java:221) 
     at org.datanucleus.identity.IdentityManagerImpl.getApplicationId(IdentityManagerImpl.java:479) 
     at org.datanucleus.ExecutionContextImpl.newObjectId(ExecutionContextImpl.java:3729) 
     at org.datanucleus.api.jdo.JDOPersistenceManager.newObjectIdInstance(JDOPersistenceManager.java:1595) 
     at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1723) 
     at Performance.DataNucleusPerfo.Read_Hbase(DataNucleusPerfo.java:109) 

的compososedIdKey

public class ComposedIdKey implements Serializable 
{ 
    public String firstName; 
    public String lastName; 
    public String dateOfBirth; 

    public ComposedIdKey() 
    { 
    } 

    /** 
    * Constructor accepting same input as generated by toString(). 
    */ 
    public ComposedIdKey(String value) 
    { 
     StringTokenizer token = new StringTokenizer (value, "::"); 
     token.nextToken();    // className 
     this.firstName = token.nextToken(); // field1 
     this.lastName = token.nextToken(); // field2l 
     this.dateOfBirth = token.nextToken(); // filed3 
    } 

    public boolean equals(Object obj) 
    { 
     if (obj == this) 
     { 
      return true; 
     } 
     if (!(obj instanceof ComposedIdKey)) 
     { 
      return false; 
     } 
     ComposedIdKey c = (ComposedIdKey)obj; 

     return firstName.equals(c.firstName) && lastName.equals(c.lastName) && dateOfBirth.equals(c.dateOfBirth); 
    } 

    public int hashCode() 
    { 
     return this.firstName.hashCode()^this.lastName.hashCode()^this.dateOfBirth.hashCode() ; 
    } 

    public String toString() 
    { 
     // Give output expected by String constructor 
     return this.getClass().getName() + "::" + this.firstName + "::" + this.lastName + "::" + this.dateOfBirth; 
    } 
} 

,我使用來獲取對象的代碼:

Transaction tx = pm.currentTransaction(); 
     System.out.println("Retrieving Customer"); 
     Customer_JDO3 teste = null; 
    try 
      { 
       tx.begin(); 
       teste = pm.getObjectById(Customer_JDO3.class,"10-10-10DataNucleus"); 

Hbase中的rowkey出現10-10-10DataNucleus

我該做什麼錯了? 謝謝

+1

錯誤是從你的代碼拋出 –

回答

2

我認爲你嘗試拆分ctor與「::」的條目,但該條目不包含這樣的字符。

+0

謝謝@mvera,這是和缺少添加類的名稱。此外,該命令必須根據ComposedIdKey類中返回的字符串。「ComposedIdKey :: Data :: Nucleus :: 10-10-10' –

相關問題