我有一个带有如此定义的ID字段的表:
create table XXX (
id uuid primary key,
name varchar,
....
我的班级XXX注释如下:
public class XXX {
@PrimaryKey
@Persistent(customValueStrategy = "uuid")
public UUID id;
...
当尝试发出PersistenceManager.makePersistent()时,我得到:
线程中的异常" main" javax.jdo.JDOFatalInternalException:为字段XXX.id生成的ID无效,ID:54e5abde-732b-42ff-af92-06af89af46ff at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:673) 在org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:720) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:740) 在Importer.save(StayImporter.java:84) 在Importer.exec(StayImporter.java:102) 在Importer.main(Importer.java:110) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497) 在com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) NestedThrowablesStackTrace: 字段XXX.id生成的ID无效,ID:54e5abde-732b-42ff-af92-06af89af46ff org.datanucleus.exceptions.NucleusException:为字段XXX.id生成的ID无效,ID:54e5abde-732b-42ff-af92-06af89af46ff at org.datanucleus.store.AbstractStoreManager.getStrategyValue(AbstractStoreManager.java:1300) at org.datanucleus.state.StateManagerImpl.populateStrategyFields(StateManagerImpl.java:2201) at org.datanucleus.state.StateManagerImpl.initialiseForPersistentNew(StateManagerImpl.java:418) at org.datanucleus.state.StateManagerImpl.initialiseForPersistentNew(StateManagerImpl.java:120) at org.datanucleus.state.ObjectProviderFactoryImpl.newForPersistentNew(ObjectProviderFactoryImpl.java:218) at org.datanucleus.ExecutionContextImpl.persistObjectInternal(ExecutionContextImpl.java:2078) at org.datanucleus.ExecutionContextImpl.persistObjectWork(ExecutionContextImpl.java:1922) at org.datanucleus.ExecutionContextImpl.persistObject(ExecutionContextImpl.java:1777) at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:715) 在org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:740)
UUID看起来不错,为什么它不起作用?
Maven是:
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-accessplatform-jdo-cassandra</artifactId>
<version>4.2.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.9</version>
</dependency>
Cassandra版本是2.2.3
答案 0 :(得分:0)
请参阅此论坛帖子:http://www.datanucleus.org/servlet/forum/viewthread_thread,7922_lastpage,yes#lastpost
摘录链接内容:
&#34; UUIDGenerator&#34;生成字符串。因此,您当前无法使用它来生成具有已发布代码的UUID值。每晚构建添加支持将String生成的值转换为TimeZone,Locale,UUID,Currency中的任何一个,因此应该使用它。
除非您可以轻松获取代码并创建自己的ValueGenerator插件,该插件扩展AbstractGenerator以生成UUID对象。