2016-05-24 3 views
0

У меня есть класс ComposedIdKey, который я использую для создания составного ключа для класса Customer. Я могу успешно вставить этот объект в Hbase с помощью составного ключа. Однако, когда я пытаюсь получить доступ этот объект получить следующее сообщение:DataNucleus + JDO: Получить объект с помощью Composite Key (ошибка: 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 отображается 10-10-10DataNucleus

Что я могу делать неправильно? Спасибо

+1

ошибка высылается из вашего кода –

ответ

2

Я думаю, что вы пытаетесь разделить запись ctor на «::», но запись не содержит таких символов.

+0

Thanks @mvera, The was this and missing добавляет имя класса. Кроме того, порядок должен быть в соответствии со строкой, возвращаемой в Class ComposedIdKey. »« ComposedIdKey :: Data :: Nucleus :: 10-10-10' –

Смежные вопросы