Skip to content


Subversion checkout URL

You can clone with
Download ZIP


support for UUID in automated mapping #95

wants to merge 2 commits into from

4 participants


I added some lines to support UUIDs as well in the automated mapping.
Since the ColumnListMutation<C> putColumn(C columnName, UUID value, Integer ttl) method already accepts UUIDs, I see no further work to be done.
I also tested it positively.


I just hit the UnsupportedOperationException when trying to use UUID with the cool Mapping feature.
I was very surprised to see that a request to fix had already been made and the fix was already done!

Great job guys!

Is there any guess as to when this fix will be available in a release?

Thanks guys!


It would be nice if you could also update the tests in to reflect the new mapping.

To update the tests you will need to add a UUID to

Otherwise great job.


I took your code fix and ran a test with it. It works pretty well but there is one small thing that I am observing that I don't know if we need to fix.

When I create a bean like:

public class TenantBean
* The id of the tenant.
private UUID tenantId;

 * The name of the tenant.
private String name;


And I have the column family defined:

TenantId uuid PRIMARY KEY,
Name text

When I try to use the Mapping like this:

ColumnFamily CF_USER = new ColumnFamily(
"Users", // Column Family Name
StringSerializer.get(), // Key Serializer
StringSerializer.get()); // Column Serializer

    Mapping<TenantBean> mapper = Mapping.make(TenantBean.class);

    // writing a bean
    MutationBatch mutationBatch = keyspace.prepareMutationBatch();

    ColumnListMutation<String> columnListMutation =
        mutationBatch.withRow(UserManagementColumnFamilies.CF_TENANT, tenantBean.getTenantId());

    mapper.fillMutation(tenantBean, columnListMutation);

It gives me an error that says:

BadRequestException: [host=, latency=3(4), attempts=1] InvalidRequestException(why:(String didn't validate.) [MyKeySpace][Tenants][TenantId] failed validation)

To see what it is trying to do, I changed my default_validator on the Tenants column family like this:

TenantId uuid PRIMARY KEY,
Name text
) WITH default_validation = BytesType;

Then I ran it again (I am trying to insert a Tenant to the column family), I noticed the following:

[default@MyKeySpace] list Tenants;
Using default limit of 100

Using default column limit of 100

RowKey: 8780602d-2a15-4fe9-b41a-b3b9debec7f2
=> (column=TenantId, value=8780602d2a154fe9b41ab3b9debec7f2, timestamp=1344887503906001)
=> (column=Name, value=SomeTenant, timestamp=1344887503906001)

See how it added the extra column TenantId. Since the default_validator is UTF8 by default, when the mapper added the new column for TenantId (Which I don't know why it does.. feels like it shoudln't), it failed in the default validator because it wanted a UTF8 instead of the UUID.

Seems like maybe we need to fix also where ever it tried to generate these columns?


I just tried it myself and I come to the same result. It does not matter which type the row key is. I tried it also for a String type row key. There is always a second row like your TenantId. I switched to manually mapping the columns which works correctly.

We need a fix in the mapping code, i think


Thank you for verifying.

I already opened an issue:


@elandau elandau closed this
@mosche mosche referenced this pull request from a commit in gini/astyanax
moritz mack FIXING #95, skip row key when mapping f9ba004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 26, 2012
  1. support for UUID in automated mapping

    Raffael Stein committed
Commits on Aug 8, 2012
  1. added test for UUID to TestMapping

    Raffael Stein committed
This page is out of date. Refresh to see the latest.
5 src/main/java/com/netflix/astyanax/mapping/
@@ -5,6 +5,7 @@
import java.lang.reflect.Field;
import java.util.Date;
+import java.util.UUID;
class Coercions {
static <T> void setFieldFromColumn(T instance, Field field,
@@ -36,6 +37,8 @@
objValue = column.getStringValue();
} else if (field.getType() == byte[].class) {
objValue = column.getByteArrayValue();
+ } else if (field.getType() == UUID.class) {
+ objValue = column.getUUIDValue();
} else {
throw new UnsupportedOperationException();
@@ -80,6 +83,8 @@
mutation.putColumn(columnName, (String) objValue, null);
} else if(objValue.getClass() == byte[].class) {
mutation.putColumn(columnName, (byte[]) objValue, null);
+ } else if (objValue.getClass() == UUID.class) {
+ mutation.putColumn(columnName, (UUID) objValue, null);
} else {
throw new UnsupportedOperationException();
8 src/test/java/com/netflix/astyanax/mapping/
@@ -1,9 +1,11 @@
+import java.util.UUID;
@SuppressWarnings({ "UnusedDeclaration", "SimplifiableIfStatement" })
public class FakeKeyspaceBean implements Comparable<FakeKeyspaceBean> {
- private String id;
+ private UUID id;
private String type;
@@ -40,7 +42,7 @@ public FakeKeyspaceBean() {
* @return value
- public String getId() {
+ public UUID getId() {
return id;
@@ -50,7 +52,7 @@ public String getId() {
* @param id
* value
- public void setId(String id) {
+ public void setId(UUID id) { = id;
8 src/test/java/com/netflix/astyanax/mapping/
@@ -3,11 +3,13 @@
import junit.framework.Assert;
import org.junit.Test;
+import java.util.UUID;
public class TestMapping {
public void testKeyspaceAnnotations() {
FakeKeyspaceBean override = new FakeKeyspaceBean();
- override.setId("1");
+ override.setId(UUID.fromString("553a6af3-14f0-419c-b257-b6c55babafe7"));
@@ -20,10 +22,10 @@ public void testKeyspaceAnnotations() {
Mapping<FakeKeyspaceBean> mapping = Mapping
- Assert.assertEquals(mapping.getIdValue(override, String.class),
+ Assert.assertEquals(mapping.getIdValue(override, UUID.class),
- mapping.getColumnValue(override, "PK", String.class),
+ mapping.getColumnValue(override, "PK", UUID.class),
"COUNTRY_OVERRIDE", String.class), override.getCountry());
Something went wrong with that request. Please try again.