我正在DataNucleus使用HBase。我有一张桌子user
。它包含4行。现在我在表格中添加了一个新列。现在,每当我访问没有此列的任何旧user
对象时,DataNucleus会尝试使用POJO中的属性映射列,从而引发异常。除了使用虚拟数据更新旧的“用户”对象之外没有其他方法吗?我的对象映射看起来像这样:
@Persistent(columns={@Column(name="next_mail_timestamp", insertValue="#NULL", defaultValue = "#NULL", allowsNull = "true")}, name="nextMailTimestamp", cacheable="false", nullValue=NullValue.DEFAULT)
private long nextMailTimestamp;
如您所见,我尝试过使用insertValue
,defaultValue
,allowsNull
,nullValue
。但似乎没有任何效果。
stacktrace看起来像这样:
at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:479)
at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:453)
at org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.fetchLongField(FetchFieldManager.java:269)
at org.datanucleus.state.AbstractStateManager.replacingLongField(AbstractStateManager.java:2133)
at com.kuliza.sitepulse.data.User.jdoReplaceField(User.java)
at com.kuliza.sitepulse.data.User.jdoReplaceFields(User.java)
at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:1989)
at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2009)
at org.datanucleus.store.hbase.query.HBaseQueryUtils$2.fetchFields(HBaseQueryUtils.java:226)
at org.datanucleus.state.JDOStateManagerImpl.loadFieldValues(JDOStateManagerImpl.java:803)
at org.datanucleus.state.JDOStateManagerImpl.initialiseForHollow(JDOStateManagerImpl.java:210)
at org.datanucleus.state.ObjectProviderFactory.newForHollowPopulated(ObjectProviderFactory.java:88)
at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2794)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectUsingApplicationIdForResult(HBaseQueryUtils.java:221)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfType(HBaseQueryUtils.java:168)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfCandidateType(HBaseQueryUtils.java:80)
at org.datanucleus.store.hbase.query.JDOQLQuery.performExecute(JDOQLQuery.java:271)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1766)
at org.datanucleus.store.query.Query.executeWithArray(Query.java:1655)
at org.datanucleus.store.query.Query.execute(Query.java:1628)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:221)
at com.kuliza.sitepulse.service.DataService.getUserWithCredentials(DataService.java:111)
at com.kuliza.sitepulse.service.AuthenticationService.getUserWithCredentials(AuthenticationService.java:46)
at com.kuliza.sitepulse.controller.AuthenticationController.signIn(AuthenticationController.java:69)
我的方法是(在DataService.java:111
中)(抛出异常)
@Override
public User getUserWithCredentials(String userName, String password){
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("SELECT FROM " + User.class.getName() + " WHERE userName == \""+userName+"\"" +" && password == " +
" \""+password + "\"");
List<User> c = (List<User>)q.execute();
pm.close();
if(c.size() > 0)
return c.get(0);
else
return null;
}
我实际上添加了两个新列(mailIntervalInMilliseconds
,nextMailTimestamp
),它们都是long
,在堆栈跟踪中我看到它试图将db列转换为Long
(AFAIK)
答案 0 :(得分:0)
DataNucleus HBase插件的发布版本目前不支持所有模式演变模式。特别是当它们是原始类型时添加字段/属性。但是DataNucleus SVN确实支持这一点,所以你可以使用它。