0
votes

I have a table with an ID field so defined:

create table XXX (
id uuid primary key,
name varchar,
....

and my class XXX is so annotated:

public class XXX {

@PrimaryKey
@Persistent(customValueStrategy = "uuid")
public UUID id;
...

When trying to issue a PersistenceManager.makePersistent(), I get:

Exception in thread "main" javax.jdo.JDOFatalInternalException: Invalid Id generated for field XXX.id, id : 54e5abde-732b-42ff-af92-06af89af46ff at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:673) at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:720) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:740) at Importer.save(StayImporter.java:84) at Importer.exec(StayImporter.java:102) at 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) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) NestedThrowablesStackTrace: Invalid Id generated for field XXX.id, id : 54e5abde-732b-42ff-af92-06af89af46ff org.datanucleus.exceptions.NucleusException: Invalid Id generated for field XXX.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) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:740)

The UUID looks good to me, why does it not work?

Maven is:

<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 version is 2.2.3

1
I would have thought all generators are normally String or Integer based. What happens if you make that field a String? Also that is not the real exception ... will be nestedNeil Stockton
I have included the nested exceptionPiero dS
With a String field, i get: org.datanucleus.exceptions.NucleusException: Invalid Id generated for XXX.id, id : 7aa194c8-06d2-491f-9ccb-4e52db36dd0aPiero dS
I have no trouble using a String field with "uuid" generationNeil Stockton
Can you show some code?Piero dS

1 Answers

0
votes

See this forum post: http://www.datanucleus.org/servlet/forum/viewthread_thread,7922_lastpage,yes#lastpost

Excerpt from linked content:

"UUIDGenerator" generates Strings. Consequently you cannot currently use it to generate UUID values with released code. Nightly builds add support for converting a String generated value to any of TimeZone, Locale, UUID, Currency, so ought to work with that.

Barring that you can easily get the code and create your own ValueGenerator plugin that extends AbstractGenerator to generate UUID objects.