DataNucleus + JDO : Retrieve an object with Composite Key (error:NoSuchElementException)
DataNucleus + JDO : Retrieve an object with Composite Key (error:NoSuchElementException)
我有一个 ComposedIdKey class,用于为客户 class 创建复合键。
我可以使用复合键成功地将这个对象插入到 Hbase 中。
但是,当我尝试访问该对象时收到以下消息:
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
我哪里做错了?
谢谢
我认为您尝试用“::”拆分 ctor 的条目,但该条目不包含此类字符。
我有一个 ComposedIdKey class,用于为客户 class 创建复合键。 我可以使用复合键成功地将这个对象插入到 Hbase 中。 但是,当我尝试访问该对象时收到以下消息:
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
我哪里做错了? 谢谢
我认为您尝试用“::”拆分 ctor 的条目,但该条目不包含此类字符。